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
Problem while executing action of a command that is called inside action of another command? #1834
Comments
Edit: this comment refers to an early version of the example code, which has been updated with much of this advice. Your example code does not have a call to This is probably the main issue: you are calling A couple of other tips, but they don't break the example:
|
I just got lucky. I went through the documentation and found this interpreter.parse(commandArr, { from : 'user'}); Adding it got my problem solved and it works as expected. Thank you for your time. const commander = require('commander')
const readline = require('readline');
const program = new commander.Command();
const interpreter = new commander.Command();
const userCommand = program.command('user');
userCommand
.action(() => {
console.log("inside user")
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
let waitForUserInput = () => {
rl.question("command > ", function(command) {
if (command == "quit"){
rl.close();
} else {
console.log("command entered is "+command)
var commandArr = command.split(" ");
const net = interpreter.command('net');
net
.command('create')
.action(() => {
console.log("create is success")
})
net
.command('remove')
.action(() => {
console.log("remove is success")
})
interpreter.parse(commandArr, { from : 'user'});
waitForUserInput()
}
});
}
waitForUserInput()
})
program.parse() |
I missed the Thanks for the update, glad you got it working. |
Action specified for the userCommand will get one more command from user using the readline function. That command is converted to a command array for parsing using the interpreter instance created. But the action for the net is not invoked when the readline reads a command from console . Below is the following code. I want the inner actions for the inner commands specified within a top level command to run .
The text was updated successfully, but these errors were encountered: