Dec-02-2019, 08:36 PM
(This post was last modified: Dec-02-2019, 08:37 PM by Gribouillis.)
Skaperen Wrote:i did not see anything about key=value arguments in that module, either.
Here is an example with plumbum.cli, a modified version of an example from the documentation
import logging from plumbum import cli logger = logging.getLogger(__name__) class MyApp(cli.Application): @cli.switch("--log-to-file", str) def log_to_file(self, filename): print('Logging to file', filename) logger.addHandler(logging.FileHandler(filename)) @cli.switch("--verbose", requires = ["--log-to-file"], excludes = ["--terse"]) def verbose(self): logger.setLevel(logging.DEBUG) @cli.switch("--terse", requires = ["--log-to-file"], excludes = ["--verbose"]) def terse(self): logger.setLevel(logging.WARNING) def main(self): logger.info('Execution of' + __file__) if __name__ == "__main__": MyApp.run()
Output:λ python3 paillasse/truccli.py --log-to-file=spam.txt --verbose
Logging to file spam.txt
As you can see, I used --log-to-file=spam.txt
and it worked.