lebrice / SimpleParsing

Simple, Elegant, Typed Argument Parsing with argparse
MIT License
428 stars 52 forks source link

Option for using only dash variants #67

Closed rggjan closed 3 years ago

rggjan commented 3 years ago

There is an option add_option_string_dash_variants:

from dataclasses import dataclass

from simple_parsing import ArgumentParser

@dataclass
class Args:
    enable_this_option: bool  # This is a nice option
    num_spiders_per_web: int = 5  # How many?

parser = ArgumentParser(add_option_string_dash_variants=True)
parser.add_arguments(Args, dest="args")

args = parser.parse_args(["--help"])

However, this always creates two versions of the same option and clutters the help:

  --enable-this-option bool, --enable_this_option bool
                        This is a nice option (default: None)
  --num-spiders-per-web int, --num_spiders_per_web int
                        How many? (default: 5)

It would be nice to have the option to disable the underscore variants and only use the dash variants (for people preferring dashes):

  --enable-this-option bool
                        This is a nice option (default: None)
  --num-spiders-per-web int
                        How many? (default: 5)
lebrice commented 3 years ago

Hey again @rggjan, thanks for posting!

Sounds good! And would also be pretty easy to add, so I'll look into this soon. I'll perhaps end up adding another Enum for the option for that, a bit like for ConflictResolution.

lebrice commented 3 years ago

Hey @rggjan, Sorry it's been a while.

I'd really appreciate someone making a PR for this, since the change would be pretty simple (and quite similar to what I describe in #75):

You'd need to either change what value is returned by the option_strings property so it only includes the full path (the dest attribute on the FieldWrapper), or filter out the option strings that are passed to the add_argument function.

In this case, there could also be some kind of enum that gets passed to the ArgumentParser constructor, that defines what style of option strings to use, something like:

class OptionStringStyle(enum.Enum):
     DEFAULT = 0
     WITH_DASHES = 1
     ONLY_DASHES = 2

Hope this helps! Let me know what you think!

rggjan commented 3 years ago

Thanks for the info and hints, makes sense! Not sure if / when I can take a look at this, though.

lebrice commented 3 years ago

Fixed by #93