Closed ghost closed 1 year ago
Oh, right. That seems reasonable. I forgot to take the subcommand parsing into account. I'll see if there's a better way to do this.
I wonder if it wouldn't generally be a better idea to have the command name be a required argument for the constructor?
It could also be optional as you mentioned, but then... what are the expected name of a subcommand that hasn't been given a name?
I know this might not be backwards-compatible, but I think it would make subparsers/parsers simpler, since it moves the responsibility for taking the wrong argument as the name of the command from the system and to the user.
Or at least I can't see how you would support nice help strings when invoking a subparser (if in the future there is more subparser support), since the subparser would need to get a name reflecting the top level command. This can currently only be done by modifying the arguments given to the subparser, which in my opinion feels very very clunky.
This can currently only be done by modifying the arguments given to the subparser, which in my opinion feels very very clunky.
Well, yes this is what I usually do. Yes, this is not very nice.
But the idea is that ArgumentParser is abstract and do not touch environment until it's specifically told to do so.
As another use case to support this, in one of the projects I use ArgumentParser to parse /proc/1234/cmdline
of another process.
If we are going to make backwards-incompatible change, like required name, I would like to other stuff too, like use OsStrings rather than Strings for argument parsing. But I don't have enough time to implement this now.
Anyway whats wrong with making title option, and fill in when doing parse()
?
It's fine, I'll have a look at implementing it soon. I think I was just worrying about the design in general ;)
Also, I'm not sure
title
is a good name. It sounds like a text before the description or something like that.set_name
may somehow be treated as a name ofArgumentParser
. Probablyset_command_name
would be okay?