You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an app with a simple requirement. Allow the user to save some data to a file, with an autogenerated name or a user-specified name. If --out is used then a generated filename (based on some data properties) is used. For a custom filename the user can use --out-file instead. I would have liked to just have one --out option that can either take an argument or be used on it's own, but there doesn't seem to be a way to do that. So sticking to mutually-exclusive --out and --out-file options. However, the mutual-exclusion check doesn't work depending on the order.
..Here's a dummy app to demonstrate the problem.
#!/usr/bin/env python
from plumbum import cli
from pprint import pprint
class MyApp(cli.Application):
_out_format = cli.SwitchAttr("out-format", cli.Set('json', 'yaml'), default='json',
help="Data format")
_out_flag = cli.Flag("out", help="Save data using an auto-generated filename",
excludes=["out-file"])
_out_file = cli.SwitchAttr("out-file", str, help="Save data using a specific filename", default=None, excludes=["out"])
def main(self):
print("out={}\n,out-file={}\n,out-format={}\n".format(self._out_flag, self._out_file,
self._out_format))
if __name__ == "__main__":
MyApp.run()
Usage..
Usage:
test.py [SWITCHES]
Meta-switches
-h, --help Prints this help message and quits
--help-all Print help messages of all subcommands and quit
-v, --version Prints the program's version and quits
Switches
--out Save data using an auto-generated filename; excludes --out-file
--out-file VALUE:str Save data using a specific filename; excludes --out
--out-format VALUE:{'yaml', 'json'} Data format; the default is 'json'
..Mutual exclusive works in this case..
~/misc/test.py --out --out-file --out-format json
Error: Given --out, the following are invalid ['--out-file']
------
Usage:
test.py [SWITCHES]
Meta-switches
-h, --help Prints this help message and quits
--help-all Print help messages of all subcommands and quit
-v, --version Prints the program's version and quits
Switches
--out Save data using an auto-generated filename; excludes --out-file
--out-file VALUE:str Save data using a specific filename; excludes --out
--out-format VALUE:{'yaml', 'json'} Data format; the default is 'json'
I have an app with a simple requirement. Allow the user to save some data to a file, with an autogenerated name or a user-specified name. If --out is used then a generated filename (based on some data properties) is used. For a custom filename the user can use --out-file instead. I would have liked to just have one --out option that can either take an argument or be used on it's own, but there doesn't seem to be a way to do that. So sticking to mutually-exclusive --out and --out-file options. However, the mutual-exclusion check doesn't work depending on the order.
..Here's a dummy app to demonstrate the problem.
Usage..
..Mutual exclusive works in this case..
But not in this case
The "--out" is eaten up as the argument for --out-file instead of reporting an error.
The text was updated successfully, but these errors were encountered: