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

Commands cannot be reused #2246

Open
gaohoward opened this issue Sep 3, 2024 · 2 comments
Open

Commands cannot be reused #2246

gaohoward opened this issue Sep 3, 2024 · 2 comments

Comments

@gaohoward
Copy link

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?

@gaohoward
Copy link
Author

looks like I can use my own options parser function... but still this is something can be improved.

@shadowspawn
Copy link
Collaborator

So basically I assume each time I have to create a new instance of the get command.

Yes, that is the intended approach.

See #2036 for some reference to past issues, and adding an explicit mention to the README.

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

3 participants
@gaohoward @shadowspawn and others