You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't want to use the git-style approach, since process spawning and requiring all libraries for every child-process is really slowing down the program (and cli uilities should be fast, shoudn't they?)
So is there a chance to define such command?
Reacted by Antoine Moreaux, Bryan Latten, Denny, Savero, Rafael Ribeiro, Santiago Aguilar Hernández, Waldek Mastykarz, Elran Kadosh, Igor, JsonSong89 and 4 more
Reacted by Savero, Santiago Aguilar Hernández, Debjeet Biswas and SHIV KUSHWAHA
var args = name.split(/ +(?=$|\[|<)/);
var cmd = new Command(args.shift());
The problem is in handling the user input. All arguments are pre-split, coming in as process.argv. This library would need to consider commands that have spaces and look for a match in the argv.
Another way to think about this is to have nested action-based commands. But it seems that this library does not support that style. It only supports one level of nesting for action-based commands.
We could split the name and stash it away on Command. Then, in parseArgs, we could do something like:
for (var i = 0; i < this.commands.length; i++) {
var names = this.commands[i]._names
if (names.length > 1) {
if (args.slice(0, names.length).join(' ') === names.join(' ')) {
this.emit('command:' + args.splice(0, names.length).join(' '), args, unknown);
return this
}
}
}
It's a bit of a hack, but we're looking for the first command that will match, taking as many of the arguments as it needs to make the match, then falling through to the existing behavior.
If that seems like a reasonable approach, I'd be happy to prepare a PR.
Reacted by Santiago Aguilar Hernández, Mikkel Damm, Waldek Mastykarz, Daniel Pedersen, Terry Sahaidak, Igor, Debjeet Biswas, Abe Tomoaki, weineel and zhe lv
The idea of specifying subcommands as a command with multiple words is quite interesting, and I had not thought of it. I like the simplicity, but it feels like a work-around rather than a strong model for how commands are constructed.
I want to consider nested action-based commands before this. I am closing this in favour of #764
Activity
sant123 commentedon Jan 3, 2018
Any advance on this?
mojavelinux commentedon Jan 10, 2018
Parsing the command is the easy part:
The problem is in handling the user input. All arguments are pre-split, coming in as process.argv. This library would need to consider commands that have spaces and look for a match in the argv.
Another way to think about this is to have nested action-based commands. But it seems that this library does not support that style. It only supports one level of nesting for action-based commands.
mojavelinux commentedon Jan 10, 2018
We could split the name and stash it away on Command. Then, in parseArgs, we could do something like:
It's a bit of a hack, but we're looking for the first command that will match, taking as many of the arguments as it needs to make the match, then falling through to the existing behavior.
mojavelinux commentedon Jan 10, 2018
If that seems like a reasonable approach, I'd be happy to prepare a PR.
waldekmastykarz commentedon Jan 27, 2018
It would be awesome if you could submit a PR for that @mojavelinux
Igor-Lopes commentedon May 30, 2018
Hello ! Any updates on this issue ?
cjmacharia commentedon Sep 26, 2018
Any updates?
grant commentedon Apr 6, 2019
Not sure if this is useful; I use
process.argv. I do something like this:https://github.com/google/clasp/blob/master/src/commands/apis.ts#L28
Seems to work fine.
shadowspawn commentedon Aug 10, 2019
The idea of specifying subcommands as a command with multiple words is quite interesting, and I had not thought of it. I like the simplicity, but it feels like a work-around rather than a strong model for how commands are constructed.
I want to consider nested action-based commands before this. I am closing this in favour of #764
Thank you for your contributions.