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

How to use options value with cmd in cmd? #167

Open
grey4owl opened this issue Jun 19, 2022 · 1 comment
Open

How to use options value with cmd in cmd? #167

grey4owl opened this issue Jun 19, 2022 · 1 comment

Comments

@grey4owl
Copy link

Hi, Is it possible to create something like this:

//-- mycli.js

const args = require("args");

args.option("port", "The port on which the app will be running.", 4040);
args.command("run", "Run dev version on localhost.", () => {
  console.log("Running on port: " + flags.port); 
  //-- this doesn't work because you cannot access 'flags' before initialization
}, ["r"]);

const flags = args.parse(process.argv);

So you can use it like: mycli run --port 3333 and then output: Running on port: 3333. In case you are not using a --port flag, the output should be: Running on port: 4040.

I did not find anything similar in the documentation..

@mike-feldmeier
Copy link

You may have already figured out the solution, but it passes a copy of flags to the function. It is defined in the "init" function documentation, but I agree it doesn't tie it together into a coherent example.

const args = require("args");

args.option("port", "The port on which the app will be running.", 4040);
args.command("run", "Run dev version on localhost.", (name, sub, options) => {
  console.log("Running on port: " + options.port); 
}, ["r"]);

args.parse(process.argv);

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