Comments (9)
@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.
Also check out https://github.com/sindresorhus/fkill-cli
https://www.npmjs.com/package/meow
https://github.com/SBoudrias/Inquirer.js/
from clasp.
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.
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.
Inquirer is complete for create
and clone
.
It's needed for deploy
, redeploy
, and version
.
from clasp.
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.
I am going to try this!
I will make PR later.
from clasp.
Do we need to migrate other functions?
from clasp.
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)
- Clasp push doesn't work now HOT 3
- Feat : clasp login with service account
- Unable to view logs when using `clasp run`
- Can't run "clasp login" command HOT 10
- Can't push local files to remote
- Provide a working solution for --no-localhost for service accounts HOT 1
- 'undefined' inside complied comment
- "No access, refresh token, API key or refresh handler callback is set." error on login HOT 2
- Clasp fails at CASA Tier 2 scan due to a vulnerability in cacheable-request at version 7.0.2 HOT 1
- Unable to use `clasp run` in Github actions workflow
- [FR] please provide option to specify port for clasp login
- Facing issue when tried to do clasp login with service account HOT 1
- Does clasp support Typescript 4.2? The latest version of ts2gas supports Typescript 4.2
- Feature request : set / get the GCP Project of the Script HOT 3
- .claspignore is not ignoring anything in it HOT 3
- 'clasp login' doesn't wait for response
- Access blocked: authorisation error when running clasp login
- Clasp claims it has pushed files even when Apps Script API is not enabled
- Clasp project dead ? HOT 3
- IMPORTANT: Clasp login may fail for new users HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clasp.