Skip to content
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

Option event listener not firing #2113

Closed
shadowspawn opened this issue Dec 25, 2023 · 2 comments
Closed

Option event listener not firing #2113

shadowspawn opened this issue Dec 25, 2023 · 2 comments

Comments

@shadowspawn
Copy link
Collaborator

shadowspawn commented Dec 25, 2023

Nice to meet you, shadowspawn , and Merry Christmas. I am a Web developer, my name is jasmin

I'd like to ask you a question and hope you can help me answer it.

Please see the bellow codes:

I have installed version 11.1.0 of Commander

npm i commander@11.1.0

And the code is defined as follows:

const commander  = require("commander");
const program = new commander.Command();
program
  .name("test-cli") 
  .usage("<command> [options]")
  .version("1.0.0")
  .option("-tp, --target-path <target-path>", "Whether to specify a local debug file path?", ""); 
program
  .command("init [projectName]")
  .option("-f, --force", "Whether to force  to init the program? ")
  .action(function (projectName, cmdObj, program)  {
  console.log("init", projectName, cmdObj, program.parent.opts());
});
program.on("option: target-path", function(){
  console.log("target path test");
});
program.parse(process.argv);

When I execute the code bellow,

test-cli init --target-path /xxx

Why it can't print the test text "target path test" ?
Can you help with this question?

Originally posted by @jasmin2014 in #1969 (comment)

@shadowspawn
Copy link
Collaborator Author

shadowspawn commented Dec 25, 2023

Close, just need to remove the space from the event name:

program.on("option:target-path", function(){
   ...
}
``

@jasmin2014
Copy link

Thank you very much. The problem has been solved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants