lebrice / SimpleParsing

Simple, Elegant, Typed Argument Parsing with argparse
MIT License
384 stars 46 forks source link

Allow to skip a field registration #244

Closed Conchylicultor closed 1 year ago

Conchylicultor commented 1 year ago

In the dataclass, it is possible to have field which should not be exposed in the CLI. It would be nice to have a way to skip registering those flags:

@dataclass
class A:
  x: int
  y: int = simple_parsing.field(register=False)

Then --x would be detected, but not --y:

my_program --x=1  # Works
my_program --y=1  # Error: Unknown FLAG --y
zhiruiluo commented 1 year ago

The dataclasses.field(init=False) would do the thing. If you use that and wanna init this field, you could still initialize it in __post_int__ function.

lebrice commented 1 year ago

Hello @Conchylicultor !

Yes there is something like this, you can use simple_parsing.field(cmd=False).

Hope this helps!

lebrice commented 1 year ago

I'll close this if that's alright with you. LMK if you have any other questions @Conchylicultor .

Thanks again for posting!

Conchylicultor commented 1 year ago

Awesome! Thank you for the quick answer