-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
On command and subcommand reusability and setting inheritance #1916
Comments
This is in accordance with how other properties containing information about the last parse call such as args & processedArgs do not get unset. Consistency in how repeated parse calls are handled could be improved by resolving tj#1916.
Thanks for the clear examples. These are all behaviours that catch an occasional person out, but have not featured in enough issues to document more explicitly or code protection against or consider changing.
Yes. Make a new Command for each call to parse, for tests or REPL. Related: #438 #1565 #1819 #1829
Yes.
Yes. The intended pattern is set the global properties on the program before adding subcommands. |
I opened #1917 to add warnings about and errors caused by wrong library usage.
Is there a specific reason why this is the expected behavior? Are there cases where building upon the result of the previous parse call is a reasonable thing to do? I cannot really think of any, so why not make repeated parse calls intuitive by simply doing the cleanup I suggested? There even seems to have been enough issues for which this change would be relevant. |
Opened #1919 with an implementation of this suggestion. |
Not a use-case reason, rather an implementation reason. Originally the code was written with a global instance and no consideration of re-use. This caused exciting conflicts when the unit testing library (also using Commander) affected the user units tests, let alone unit tests conflicting with each other. The approach to make a new |
All of the behaviours are as expected. I will continue to monitor issues for support for updating the documentation or changing the behaviour. Of the three, I think Thank you for your contributions. |
Is it expected behavior that
parse()
/parseAsync()
are only correctly callable once, since the command's properties get polluted with the result of the previous call?I think it should not be expected. Use cases for repeated calls include testing and interactive command parsing.
Here is an example:
If it is not expected, a possible solution is to do a cleanup at the beginning of
parse()
/parseAsync()
.Is it expected behavior that explicitly constructed subcommands are tightly bound to one parent command and cannot be used as stand-alone commands or as subcommands of multiple parent commands?
Here is an example:
If it is not expected, a possible solution is to not set the
parent
property on subcommands incommand()
andaddCommand()
but in_dispatchSubcommand()
instead, and unset it before returning.If it is expected, an error should be thrown when trying to parse or adopt a command that already has a parent.
Is it expected behavior that implicitly constructed subcommands added with
command()
only inherit settings upon construction?Here is an example:
If it is not expected, a possible solution is to not call
copyInheritedSettings()
on subcommands added withcommand()
upon construction but in_dispatchSubcommand()
instead.If it is expected, a note on this in the docs would be nice.
The text was updated successfully, but these errors were encountered: