Major improvements, deduplication and simplification in over.app.
- over.app.ConfigFile can create empty config files and read all options from them - over.callback was created to hold commandline parser callbacks - over.app.Option.is_boolean hint added - major improvements and increased robustness of over.app.Main command line parser
This commit is contained in:
parent
720dfa7b09
commit
2757cd8e96
6 changed files with 247 additions and 69 deletions
21
test.py
21
test.py
|
@ -21,20 +21,21 @@ class ConfigurationError(Exception):
|
|||
|
||||
# --------------------------------------------------
|
||||
|
||||
def tag_callback(tag, value):
|
||||
return "%s: %s" %(tag, value)
|
||||
def noop(*args):
|
||||
return args
|
||||
|
||||
def tri_callback(a, b, c):
|
||||
return "%s, %s and %s" %(a, b, c)
|
||||
def int4(*args):
|
||||
return [int(x) for x in args]
|
||||
|
||||
if __name__ == "__main__":
|
||||
main = over.app.Main("Over App Test", version.str, "LICENSE")
|
||||
main = over.app.Main("new-over-test", version.str, "LICENSE", features={"config_file": True})
|
||||
# name, description, callback, default=Option_sources.none, count=0, overwrite=True, abbr=None, in_cfg_file=True, show_in_help=True
|
||||
main.add_option("armed", "Description.", bool, True, abbr="A")
|
||||
main.add_option("verbose", "Description.", bool, True, abbr="v")
|
||||
main.add_option("read", "Description.", str, ["test"], count=1, overwrite=False, abbr="R")
|
||||
main.add_option("tag", "Description.", tag_callback, [], count=2, overwrite=False, abbr="t")
|
||||
main.add_option("tristate", "Description.", tri_callback, [], count=3, overwrite=True)
|
||||
main.add_option("boolean-single", "", over.callback.boolean, [False], abbr="1")
|
||||
main.add_option("boolean-triple", "", over.callback.booleans, [False, False, False], abbr="3", count=3)
|
||||
main.add_option("str-single", "", str, ["kek"], abbr="s", count=1)
|
||||
main.add_option("str-quad", "", noop, ["ze", "kek", "is", "bek"], abbr="4", count=4)
|
||||
main.add_option("int-quad", "", int4, [45, 72, 97, 18], abbr="i", count=4)
|
||||
main.add_option("int-quad-multi", "", int4, [45, 72, 97, 18], abbr="I", count=4, overwrite=False)
|
||||
main.add_doc("Description", ["What it does.", "Another paragraph."])
|
||||
main.parse()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue