tailhook / rust-argparse

The command-line argument parser library for rust
MIT License
240 stars 39 forks source link

Add a 'set_title' option to the argument parser and tidy up the documentation a bit #30

Closed ghost closed 1 year ago

tailhook commented 8 years ago

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 of ArgumentParser. Probably set_command_name would be okay?

ghost commented 8 years 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.

ghost commented 8 years ago

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.

tailhook commented 8 years ago

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() ?

ghost commented 8 years ago

It's fine, I'll have a look at implementing it soon. I think I was just worrying about the design in general ;)