Can't prompt for more input when running action selected in CLI options
- Dominant language
- JavaScript
- Stars
- 5.6k
- Forks
- 278
- PR merge metrics
- No merged PRs in 30d
Description
Using code provided in https://github.com/dthree/vorpal/issues/171#issuecomment-298230095 I can't use `this.prompt()` to ask user additional things. Obviously this is due to ui.js requiring to have some `parent` which is missing then.
According to the template given in comment linked before, when I write an action like this:
```javascript
Vorpal
.command( "some-cmd", "some command" )
.action( function( args, cb ) {
Promise.resolve( this.prompt( [ {
type: "string",
message: "enter your name: ",
name: "username",
} ] )
.then( repl ? cb : null );
} );
```
the prompt is showing up when running in REPL mode, but it's omitted when running script with `some-cmd` selected on CLI like this:
```base
$ node myscript.js some-cmd
```
I was able to fix this issue by explicitly assigning current command's parent to the UI prior to prompting but I bet this isn't safe due to monkey-patching some more static part of Vorpal from a more instance-like part of code.
```javascript
Vorpal
.command( "some-cmd", "some command" )
.action( function( args, cb ) {
if ( !repl && !Vorpal.ui.parent ) {
Vorpal.ui.parent = this.parent;
}
Promise.resolve( this.prompt( [ {
type: "string",
message: "enter your name: ",
name: "username",
} ] )
.then( repl ? cb : null );
} );
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.