Skip to content

Accessing parent options from subcommand #243

Closed
@marc0s

Description

@marc0s

Are parent's options available to subcommands? In my tests, they aren't.

It would be nice to have them available. In my case is for configuring the remote server my CLI app needs to connect to, so I have not to define the same options in every subcommand.

# ./cmd
#!/usr/bin/env node

var program = require("commander");
program.version("0.0.1")
  .option("-H, --host <host>", "server host")
  .command("sub", "subcommand");
program.parse(process.argv);
console.log(program.host);

# ./cmd-sub
#!/usr/bin/env node

var program = require("commander");
program.version("0.0.1");
program.parse(process.argv);
console.log(program.host);

And if you run them:

$ ./cmd --host localhost 
localhost
$ ./cmd-sub --host localhost 
error: unknown option `--host'

Any trick to get them from the subcommand or is just not possible?

Thanks.

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