parent
8996bb9d04
commit
16770b209c
3 changed files with 35 additions and 6 deletions
|
@ -754,6 +754,7 @@ class Main:
|
|||
else:
|
||||
method = None
|
||||
method_display_name = "<y>%s<.>" %(method_name)
|
||||
|
||||
if method_name == "<module>":
|
||||
method_type = "module"
|
||||
else:
|
||||
|
|
|
@ -3,6 +3,10 @@
|
|||
|
||||
# --------------------------------------------------
|
||||
|
||||
import os
|
||||
|
||||
# --------------------------------------------------
|
||||
|
||||
def boolean(arg):
|
||||
"""
|
||||
Converts
|
||||
|
@ -48,3 +52,29 @@ def strings(*args):
|
|||
out.append(str(arg))
|
||||
|
||||
return out
|
||||
|
||||
def directory(exists=False, writable=False, gio=False):
|
||||
"""
|
||||
Returns a directory callback that raises hell if:
|
||||
- the supplied directory doesn't exist and `exists` is True
|
||||
- isn't writable and `writable` is True
|
||||
- isn't a valid Gio path and `gio` is True
|
||||
|
||||
@while generating a callback
|
||||
"""
|
||||
|
||||
if gio:
|
||||
raise NotImplementedError("Gio support is not yet here")
|
||||
|
||||
def cb(arg):
|
||||
path = os.path.abspath(os.path.expanduser(arg))
|
||||
|
||||
if not os.path.isdir(path) and exists:
|
||||
raise FileNotFoundError("%s (%s) does not exist" %(arg, path))
|
||||
|
||||
if writable and not os.access(path, os.W_OK | os.X_OK):
|
||||
raise PermissionError("%s exists but is not writable" %(arg))
|
||||
|
||||
return path
|
||||
|
||||
return cb
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
# --------------------------------------------------
|
||||
# Library imports
|
||||
import over
|
||||
prefix = over.text.prefix
|
||||
|
||||
# --------------------------------------------------
|
||||
# Local imports
|
||||
|
@ -25,10 +24,9 @@ class ConfigurationError(Exception):
|
|||
# --------------------------------------------------
|
||||
|
||||
if __name__ == "__main__":
|
||||
main = over.app.Main("short-name", "Human Readable Name", version.str, "LICENSE", use_cfg_file=False)
|
||||
main.add_option("option", "type", "default", "Description.", short_name="s")
|
||||
main.add_help("Description", ["What it does.", "Another paragraph."])
|
||||
main.enable_help("h")
|
||||
main.parse()
|
||||
main = over.app.Main("app-name", version.str, "LICENSE", features={"config_file": False})
|
||||
main.add_option("option", "What the option does.", str, ["default"], count=1, abbr="o")
|
||||
main.add_doc("Description", ["What it does.", "Another paragraph."])
|
||||
main.setup()
|
||||
|
||||
...
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue