diff --git a/over/app.py b/over/app.py index 07a14f8..46cc603 100644 --- a/over/app.py +++ b/over/app.py @@ -754,6 +754,7 @@ class Main: else: method = None method_display_name = "%s<.>" %(method_name) + if method_name == "": method_type = "module" else: diff --git a/over/callback.py b/over/callback.py index 3f5d807..aa55678 100644 --- a/over/callback.py +++ b/over/callback.py @@ -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 diff --git a/over/template.py b/over/template.py index b7bb9c7..6502007 100644 --- a/over/template.py +++ b/over/template.py @@ -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() ...