lebrice / SimpleParsing

Simple, Elegant, Typed Argument Parsing with argparse
MIT License
399 stars 49 forks source link

Alias prefix suppression #159

Closed idoby closed 1 year ago

idoby commented 2 years ago

Allow to suppress the prefix defined for a field if used through an alias, for extra-short aliases for often-used command line switches.

idoby commented 2 years ago

@lebrice Something seems to be wrong with the 3.6 check. Didn't you drop support for 3.6?

lebrice commented 2 years ago

Yeah support was dropped for python 3.6, and I'm not quite sure why it still shows up here... Fixed!

lebrice commented 2 years ago

Hey @idoby, wouldn't passing field(alias="--out")be sufficient here? If not, would you mind clarifying why this is required?

idoby commented 2 years ago

Hey @idoby, wouldn't passing field(alias="--out")be sufficient here? If not, would you mind clarifying why this is required?

I'm using prefixes, so specifying aliases still keeps the prefix (e.g. "--experiment_label" becomes "-experiment_l" instead of "-l") and I got tired of typing out the entire thing. So I made a way to drop the prefix for often used cmdline switches.

lebrice commented 2 years ago

How would you deal with a dataclass with an "Alias" field being used in two different places?

idoby commented 2 years ago

How would you deal with a dataclass with an "Alias" field being used in two different places?

That would be a conflict. I didn't really get into the details of how AP/SP does conflict resolution, just assumed it would throw an error or something. Do you think this will be a problem?

lebrice commented 1 year ago

Wait, @idoby , I'm not sure you answered my question:

wouldn't passing field(alias="--out") be sufficient here? (iirc it doesn't use a prefix in that case, right?)

idoby commented 1 year ago

wouldn't passing field(alias="--out") be sufficient here? (iirc it doesn't use a prefix in that case, right?)

No, because I'm using a dataclass called ExperimentConfig which is sent to SP with a prefix, namely "experiment". This DC contains a "label" field with alias "-l", which then becomes "-experiment_l" instead of "-l" like I wanted.

I've included examples in test_aliases_with_suppressed_prefix() in test/test_aliases.py.

lebrice commented 1 year ago

I'm not convinced yet that this is a feature worth adding. Closing for now.