Skip to content

this.name is not a function when a subcommand with option --name is used #1282

@sn0wcat

Description

@sn0wcat

Commander in version 5.1.0 seems to have problems with option called name in subcommand

this typescript command snippet works:

program
        .command("create-agent")
        .alias("ca")
        .option("-c, --config <agentconfig>", "config file for agent configuration")
        .option(
            "-r, --cert [privatekey]",
            "required for agents with RSA_3072 profile. create with: openssl genrsa -out private.key 3072"
        )
        .option("-n, --agentname <agentname>", "agent name", `Agent${Date.now()}`)
        .option("-p, --parentid <parentid>", "parent asset id")
        .option("-f, --profile <profile>", "security profile [SHARED_SECRET|RSA_3072]", "SHARED_SECRET")
        .option("-k, --passkey <passkey>", "passkey")
        .option("-y, --retry <number>", "retry attempts before giving up", "3")
        .option("-v, --verbose", "verbose output")
        .description(color("create an agent in the mindsphere *"))
        .action((options) => {
            (async () => {

but replace the --agentname with --name in options

 .option("-n, --name <name>", "agent name", `Agent${Date.now()}`)

and you will get a following exception:

C:\git\github\mindconnect-nodejs\node_modules\commander\index.js:916
        this.emit('command:' + this.name(), operands, unknown);
                                   ^

TypeError: this.name is not a function
    at Command._parseCommand (C:\git\github\mindconnect-nodejs\node_modules\commander\index.js:916:37)
    at Command._dispatchSubcommand (C:\git\github\mindconnect-nodejs\node_modules\commander\index.js:865:18)
    at Command._parseCommand (C:\git\github\mindconnect-nodejs\node_modules\commander\index.js:882:12)
    at Command.parse (C:\git\github\mindconnect-nodejs\node_modules\commander\index.js:717:10)
    at Object.<anonymous> (C:\git\github\mindconnect-nodejs\src\cli\mc.js:84:9)
    at Module._compile (internal/modules/cjs/loader.js:1158:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
    at Module.load (internal/modules/cjs/loader.js:1002:32)
    at Function.Module._load (internal/modules/cjs/loader.js:901:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
    at internal/main/run_main_module.js:18:47

Used node version

$ node --version
v12.16.1

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