bw2 / ConfigArgParse

A drop-in replacement for argparse that allows options to also be set via config files and/or environment variables.
MIT License
719 stars 121 forks source link

[feature request] Method to remove argument by name #262

Open vvch opened 2 years ago

vvch commented 2 years ago

Method to remove argument by name.

Seems useless at first glance, but may be very helpful when there is a bunch of similar programs which inherit from each other. E. g.

class Program1:
    def __init__(self):
        self.argparser = ArgumentParser(...)
        self.argparser.add()
        ...
        self.argparser.add()  #  lots of arguments

    def run(self):
        args = self.argparser.parse()
        #  Program workflow
        ...

class Program2(Program1):
    def __init__(self):
        super().__init__()
        self.argparser.add('additional argument specific to Program2 only')
        self.argparser.remove('argument useless in Program2')  #  <-- method to be added

It would be useful to have official API to do this trick.

bw2 commented 2 years ago

Unless / until more people request this, perhaps you can implement it by creating your own subclass of ConfigArgParse (or by accessing internal data structures like self._actions)?

(If you do, please post it here)