andrey-zherikov / argparse

Parser for command-line arguments
https://andrey-zherikov.github.io/argparse/
Boost Software License 1.0
31 stars 6 forks source link

Affect usage description for a main program? #74

Closed schveiguy closed 2 years ago

schveiguy commented 2 years ago

For a subcommand, you can affect the description by attributing the command with information.

But I want to just add a description for the whole program. Is that possible to do?

andrey-zherikov commented 2 years ago

Did you try Command attribute?

@(Command.Description("Description for the whole program"))
struct MainProgram
{
...
}
schveiguy commented 2 years ago

Does that work? Because I thought Command required a parameter of the program name. I tried Command().Description(...) and it failed to compile.

I'll check when I get a chance.

schveiguy commented 2 years ago

To be clearer, I want to use the automatic mechanism that detects the program name (I'm assuming from argv[0]) and uses that for the usage, but still provides a nice description.

My current implementation uses Command("foo").Description(...) and it works, where "foo" is the program name. This is OK if there is no other way, but I would prefer to be more DRY.

andrey-zherikov commented 2 years ago

It should work - if you don't specify command name then it's gonna use argv[0]. Let me know if it does not.

andrey-zherikov commented 2 years ago

I just checked with one of the examples - compilation failed. I'll fix it.

andrey-zherikov commented 2 years ago

@schveiguy I added this to example:

@(Command.Description("Description of main program"))
struct Program
{
...
}
schveiguy commented 2 years ago

Thanks!