Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from commander to inquirer #57

Closed
grant opened this issue Mar 6, 2018 · 9 comments
Closed

Switch from commander to inquirer #57

grant opened this issue Mar 6, 2018 · 9 comments
Milestone

Comments

@grant
Copy link
Contributor

grant commented Mar 6, 2018

Give autocompletion for `clasp commands.

Vorpal seems to be based on commander and provides these features.

@grant
Copy link
Contributor Author

grant commented Mar 18, 2018

@grant grant changed the title Switch from commander to vorpal Switch from commander to inquirer Mar 19, 2018
@grant
Copy link
Contributor Author

grant commented Mar 21, 2018

Example prompt:

/**
 * List prompt example
 */
var inquirer = require('inquirer');
var _ = require('lodash');
var fuzzy = require('fuzzy');
var Promise = require('promise');
inquirer.registerPrompt('autocomplete', require('./index'));

var states = [
  'Alabama',
  'Alaska',
  'West Virginia',
  'Wisconsin',
  'Wyoming'
];

var foods = [
  'Apple',
  'Grapefruit',
];

function searchStates(answers, input) {
  input = input || '';
  return new Promise(function(resolve) {
    var fuzzyResult = fuzzy.filter(input, states);
    resolve(fuzzyResult.map(function(el) {
      return el.original;
    }));
  });
}


function searchFood(answers, input) {
  input = input || '';
  return new Promise(function(resolve) {
    var fuzzyResult = fuzzy.filter(input, foods);
    resolve(fuzzyResult.map(function(el) {
      return el.original;
    }));
  });
}

inquirer.prompt([{
  type: 'autocomplete',
  name: 'fruit',
  // suggestOnly: true,
  message: 'What is your favorite fruit?',
  source: searchFood,
  pageSize: 4,
  validate: function(val) {
    return val
      ? true
      : 'Type something!';
  }
}, {
  type: 'autocomplete',
  name: 'state',
  message: 'Select a state to travel from',
  source: searchStates
}]).then(function(answers) {
  console.log(JSON.stringify(answers, null, 2));
});

@grant grant added this to the Clasp V2 milestone Apr 6, 2018
@grant
Copy link
Contributor Author

grant commented Apr 17, 2018

So I've look at this for a bit today. There seems to not be an ideal solution that fits for clasp.

The issues are multifold.

  • I'd expect clasp to be executed from a bash script as well as a user.
  • It seems tab autocompletion is not possible without bash rc modification (which I don't want to do).

Command Prompt Options

Inquirer: Too basic. Can't take specific commands, treats everything as global.
Vorpal: Seems like the best choice, BUT it only supports an enclosed environment. (You must start the command line system).
Commander: Wraps inquirer with some state (allows subcommands). But no interactive selection
yargs: Too simple. Able to parse args but has no context.

Here's a good tutorial of combining commander and inquirer: https://scotch.io/tutorials/build-an-interactive-command-line-application-with-nodejs

Commands

I think clasp@2 should use commander and inquirer in this combination to provide an easy, simple experience for Apps Script developers.

# Commander
clasp # If there's no clasp project, displays help. If there's a clasp project, watch.
clasp login
clasp logout
clasp pull
clasp push [--watch]
clasp open
clasp deployments
clasp versions
clasp list
clasp logs [--json] [--open]

# Inquirer enhancement (leave off the arg and it'll prompt you)
clasp create  [scriptTitle] [scriptParentId] – These can be prompted by the user
clasp clone <scriptId> – clasp list the scriptId.
clasp deploy [version] [description] - clasp deploy would prompt the user
clasp redeploy ... - clasp redeploy would prompt the user
clasp version - clasp version would prompt the user

Summary

I think a combination of commander (for base command structure) and inquirer (for extra selection features) should be the technology decision for powering the clasp CLI.

@grant
Copy link
Contributor Author

grant commented Jun 1, 2018

Inquirer is complete for create and clone.
It's needed for deploy, redeploy, and version.

@takanakahiko
Copy link
Contributor

I am going to try this!
I will make PR later.

@takanakahiko
Copy link
Contributor

Do we need to migrate other functions?

@grant
Copy link
Contributor Author

grant commented Nov 20, 2018

@takanakahiko It would be nice if clasp create was fixed to prompt the user of which type of add-on to create if --type isn't specified.

The 2.0 interface is described here:
https://github.com/google/clasp#create

@grant
Copy link
Contributor Author

grant commented Apr 6, 2019

I may have to revisit this and use the up and rising CLI framework oclif:
https://github.com/oclif/oclif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants