Skip to content

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

@grey4owl

Description

@grey4owl

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..

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions