Giter VIP home page Giter VIP logo

Comments (9)

grant avatar grant commented on June 14, 2024 1

@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

from clasp.

grant avatar grant commented on June 14, 2024

Also check out https://github.com/sindresorhus/fkill-cli
https://www.npmjs.com/package/meow
https://github.com/SBoudrias/Inquirer.js/

from clasp.

grant avatar grant commented on June 14, 2024

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));
});

from clasp.

grant avatar grant commented on June 14, 2024

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.

from clasp.

grant avatar grant commented on June 14, 2024

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

from clasp.

grant avatar grant commented on June 14, 2024

Also see:
https://cloud.google.com/sdk/docs/interactive-gcloud

https://github.com/dthree/vorpal/wiki/Docs-%7C-Autocomplete
https://www.npmjs.com/package/prompt-autocompletion

from clasp.

takanakahiko avatar takanakahiko commented on June 14, 2024

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

from clasp.

takanakahiko avatar takanakahiko commented on June 14, 2024

Do we need to migrate other functions?

from clasp.

grant avatar grant commented on June 14, 2024

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

from clasp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.