Skip to content

Commands cannot be reused #2246

@gaohoward

Description

@gaohoward

Hi I'm trying to create a cli app (interactive) that uses commands to perform tasks. For each task I create a command instance.
For example I provide a get command for user to use.

const getCmd = program.command('get')
.description('get information from a endpoint')
.argument('<path>', 'path of the component, [endpointName/componentType]')
.argument('[compName]', 'name of the component', '')
.option('-a, --attributes [attributeNames...]', 'get attributes from component', '')
.action(async (path, compName, options, cmd) => {
...
});

In the interactive shell (I use readline lib) if user input get args opts the getCmd will called
getCmd.parseAsync(allargs [])

then after the command is executed, the shell waiting for next command, if user inputs the same get command but with some options removed, when it calls the getCmd.parseAsync(allargs) again I found some of the options from the first execution remains.

So basically I assume each time I have to create a new instance of the get command. I wonder if there is a way to reset the command for reuse?

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