def handle_cli_command(self, config): """Handle a command from the CLI. """ cmd = config["cli_command"] # aliases if cmd[0] in ["mod", "module", "modules"]: cmd[0] = "modules" # allowed cli commands if cmd[:2] in (["modules", "list"], ["modules", "details"]): docstrings.show_modules(config, cmd[1:]) # docstring formatting and checking elif cmd[:2] in (["docstring", "check"], ["docstring", "update"]): if cmd[1] == "check": show_diff = len(cmd) > 2 and cmd[2] == "diff" docstrings.check_docstrings(show_diff, config) if cmd[1] == "update": if len(cmd) < 3: print_stderr("Error: you must specify what to update") sys.exit(1) if cmd[2] == "modules": docstrings.update_docstrings() else: docstrings.update_readme_for_modules(cmd[2:]) elif cmd[:2] in (["modules", "enable"], ["modules", "disable"]): # TODO: to be implemented pass else: print_stderr("Error: unknown command") sys.exit(1)
def handle_cli_command(self, config): """Handle a command from the CLI. """ cmd = config['cli_command'] # aliases if cmd[0] in ['mod', 'module', 'modules']: cmd[0] = 'modules' # allowed cli commands if cmd[:2] in (['modules', 'list'], ['modules', 'details']): docstrings.show_modules(config, cmd[1:]) # docstring formatting and checking elif cmd[:2] in (['docstring', 'check'], ['docstring', 'update']): if cmd[1] == 'check': show_diff = len(cmd) > 2 and cmd[2] == 'diff' if show_diff: mods = cmd[3:] else: mods = cmd[2:] docstrings.check_docstrings(show_diff, config, mods) if cmd[1] == 'update': if len(cmd) < 3: print_stderr('Error: you must specify what to update') sys.exit(1) if cmd[2] == 'modules': docstrings.update_docstrings() else: docstrings.update_readme_for_modules(cmd[2:]) elif cmd[:2] in (['modules', 'enable'], ['modules', 'disable']): # TODO: to be implemented pass else: print_stderr('Error: unknown command') sys.exit(1)
def handle_cli_command(self, config): """Handle a command from the CLI. """ cmd = config['cli_command'] # aliases if cmd[0] in ['mod', 'module', 'modules']: cmd[0] = 'modules' # allowed cli commands if cmd[:2] in (['modules', 'list'], ['modules', 'details']): docstrings.show_modules(config, cmd[1:]) # docstring formatting and checking elif cmd[:2] in (['docstring', 'check'], ['docstring', 'update']): if cmd[1] == 'check': show_diff = len(cmd) > 2 and cmd[2] == 'diff' docstrings.check_docstrings(show_diff, config) if cmd[1] == 'update': if len(cmd) < 3: print_stderr('Error: you must specify what to update') sys.exit(1) if cmd[2] == 'modules': docstrings.update_docstrings() else: docstrings.update_readme_for_modules(cmd[2:]) elif cmd[:2] in (['modules', 'enable'], ['modules', 'disable']): # TODO: to be implemented pass else: print_stderr('Error: unknown command') sys.exit(1)
def handle_cli_command(self, config): """Handle a command from the CLI. """ cmd = config["cli_command"] # aliases if cmd[0] in ["mod", "module", "modules"]: cmd[0] = "modules" # allowed cli commands if cmd[:2] in (["modules", "list"], ["modules", "details"]): docstrings.show_modules(config, cmd[1:]) # docstring formatting and checking elif cmd[:2] in (["docstring", "check"], ["docstring", "update"]): if cmd[1] == "check": show_diff = len(cmd) > 2 and cmd[2] == "diff" if show_diff: mods = cmd[3:] else: mods = cmd[2:] docstrings.check_docstrings(show_diff, config, mods) if cmd[1] == "update": if len(cmd) < 3: print_stderr("Error: you must specify what to update") sys.exit(1) if cmd[2] == "modules": docstrings.update_docstrings() else: docstrings.update_readme_for_modules(cmd[2:]) elif cmd[:2] in (["modules", "enable"], ["modules", "disable"]): # TODO: to be implemented pass else: print_stderr("Error: unknown command") sys.exit(1)
def parse_list_or_docstring(options, sps): """ Handle py3-cmd list and docstring options. """ import py3status.docstrings as docstrings # HARDCODE: make include path to search for user modules home_path = os.path.expanduser("~") xdg_home_path = os.environ.get("XDG_CONFIG_HOME", "{}/.config".format(home_path)) options.include_paths = [ "{}/py3status/modules".format(xdg_home_path), "{}/i3status/py3status".format(xdg_home_path), "{}/i3/py3status".format(xdg_home_path), "{}/.i3/py3status".format(home_path), ] include_paths = [] for path in options.include_paths: path = os.path.abspath(path) if os.path.isdir(path) and os.listdir(path): include_paths.append(path) options.include_paths = include_paths # init config = vars(options) modules = [x.rsplit(".py", 1)[0] for x in config["module"]] # list module names and details if config["command"] == "list": tests = [not config[x] for x in ["all", "user", "core"]] if all([not modules] + tests): msg = "missing positional or optional arguments" sps["list"].error(msg) docstrings.show_modules(config, modules) # docstring formatting and checking elif config["command"] == "docstring": if config["check"]: docstrings.check_docstrings(False, config, modules) elif config["diff"]: docstrings.check_docstrings(True, config, None) elif config["update"]: if not modules: msg = "missing positional arguments or `modules`" sps["docstring"].error(msg) if "modules" in modules: docstrings.update_docstrings() else: docstrings.update_readme_for_modules(modules) else: msg = "missing positional or optional arguments" sps["docstring"].error(msg)
def parse_list_or_docstring(options, sps): """ Handle py3-cmd list and docstring options. """ import py3status.docstrings as docstrings # HARDCODE: make include path to search for user modules home_path = os.path.expanduser("~") xdg_home_path = os.environ.get("XDG_CONFIG_HOME", "{}/.config".format(home_path)) options.include_paths = [ "{}/py3status/modules".format(xdg_home_path), "{}/i3status/py3status".format(xdg_home_path), "{}/i3/py3status".format(xdg_home_path), "{}/.i3/py3status".format(home_path), ] include_paths = [] for path in options.include_paths: path = os.path.abspath(path) if os.path.isdir(path) and os.listdir(path): include_paths.append(path) options.include_paths = include_paths # init config = vars(options) modules = [x.rsplit(".py", 1)[0] for x in config["module"]] # list module names and details if config["command"] == "list": tests = [not config[x] for x in ["all", "user", "core"]] if all([not modules] + tests): msg = "missing positional or optional arguments" sps["list"].error(msg) docstrings.show_modules(config, modules) # docstring formatting and checking elif config["command"] == "docstring": if config["check"]: docstrings.check_docstrings(False, config, modules) elif config["diff"]: docstrings.check_docstrings(True, config, None) elif config["update"]: if not modules: msg = "missing positional arguments or `modules`" sps["docstring"].error(msg) if "modules" in modules: docstrings.update_docstrings() else: docstrings.update_readme_for_modules(modules) else: msg = "missing positional or optional arguments" sps["docstring"].error(msg)
def parse_list_or_docstring(options, sps): """ Handle py3-cmd list and docstring options. """ import py3status.docstrings as docstrings # HARDCODE: make include path to search for user modules home_path = Path.home() xdg_home_path = Path( os.environ.get("XDG_CONFIG_HOME", home_path / ".config")).resolve() options.include_paths = [ xdg_home_path / "py3status/modules", xdg_home_path / "i3status/py3status", xdg_home_path / "i3/py3status", home_path / ".i3/py3status", ] include_paths = [] for path in options.include_paths: if path.is_dir() and any(path.iterdir()): include_paths.append(path) options.include_paths = include_paths # init config = vars(options) modules = [Path(x).stem for x in config["module"]] # list module names and details if config["command"] == "list": tests = [not config[x] for x in ["all", "user", "core"]] if all([not modules] + tests): msg = "missing positional or optional arguments" sps["list"].error(msg) docstrings.show_modules(config, modules) # docstring formatting and checking elif config["command"] == "docstring": if config["check"]: docstrings.check_docstrings(False, config, modules) elif config["diff"]: docstrings.check_docstrings(True, config, None) elif config["update"]: if not modules: msg = "missing positional arguments or `modules`" sps["docstring"].error(msg) if "modules" in modules: docstrings.update_docstrings() else: docstrings.update_readme_for_modules(modules) else: msg = "missing positional or optional arguments" sps["docstring"].error(msg)