From 7000139f9f294d862d00b10f6081dec07c944cd7 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Fri, 17 Mar 2023 10:37:02 +0200 Subject: [PATCH] Updated for help --- slpkg/main.py | 53 ++++++++++++++++++++++------------------- slpkg/views/cli_menu.py | 4 ++-- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/slpkg/main.py b/slpkg/main.py index a504938c..b6d98d83 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -53,7 +53,7 @@ class Argparse(Configs): self.file_pattern = self.file_pattern_conf if len(self.args) == 0 or '' in self.args: - self.usage.help_short() + self.usage.help_short(1) self.check.is_blacklist(self.args) @@ -285,10 +285,13 @@ class Argparse(Configs): self.usage.help_minimal() # Fixed for correct options by command. - options = self.commands[self.args[0]] - for opt in self.flags: - if opt not in options: - invalid.append(opt) + try: + options = self.commands[self.args[0]] + for opt in self.flags: + if opt not in options: + invalid.append(opt) + except (KeyError, IndexError): + self.usage.help_short(1) # Prints error for invalid options. if invalid: @@ -421,21 +424,21 @@ class Argparse(Configs): def help(self) -> None: if len(self.args) == 1: self.usage.help(0) - self.usage.help(1) + self.usage.help_short(1) def version(self) -> None: if len(self.args) == 1: version = Version() version.view() raise SystemExit() - self.usage.help(1) + self.usage.help_short(1) def update(self) -> None: if len(self.args) == 1: update = UpdateRepository(self.flags) update.repository() raise SystemExit() - self.usage.help(1) + self.usage.help_short(1) def upgrade(self) -> None: command = Argparse.upgrade.__name__ @@ -455,7 +458,7 @@ class Argparse(Configs): install = Slackbuilds(packages, self.flags, self.file_pattern, mode=command) install.execute() raise SystemExit() - self.usage.help(1) + self.usage.help_short(1) def check_updates(self) -> None: if len(self.args) == 1: @@ -463,13 +466,13 @@ class Argparse(Configs): check = CheckUpdates() check.updates() raise SystemExit() - self.usage.help(1) + self.usage.help_short(1) def edit_configs(self) -> None: if len(self.args) == 1: self.form_configs.edit() raise SystemExit() - self.usage.help(1) + self.usage.help_short(1) def clean_logs(self) -> None: if len(self.args) == 1: @@ -478,7 +481,7 @@ class Argparse(Configs): logs = CleanLogsDependencies(self.flags) logs.clean() raise SystemExit() - self.usage.help(1) + self.usage.help_short(1) def clean_tmp(self) -> None: if len(self.args) == 1: @@ -495,14 +498,14 @@ class Argparse(Configs): print(f"The folder '{self.tmp_path}{self.prog_name}' was cleaned!") raise SystemExit() - self.usage.help(1) + self.usage.help_short(1) def clean_data(self) -> None: if len(self.args) == 1: update = UpdateRepository(self.flags) update.drop_the_tables() raise SystemExit() - self.usage.help(1) + self.usage.help_short(1) def build(self) -> None: command = Argparse.build.__name__ @@ -521,7 +524,7 @@ class Argparse(Configs): build = Slackbuilds(packages, self.flags, self.file_pattern, mode=command) build.execute() raise SystemExit() - self.usage.help(1) + self.usage.help_short(1) def install(self) -> None: command = Argparse.install.__name__ @@ -540,7 +543,7 @@ class Argparse(Configs): install = Slackbuilds(packages, self.flags, self.file_pattern, mode=command) install.execute() raise SystemExit() - self.usage.help(1) + self.usage.help_short(1) def download(self) -> None: command = Argparse.download.__name__ @@ -557,7 +560,7 @@ class Argparse(Configs): download = Download(self.directory, self.flags) download.packages(packages) raise SystemExit() - self.usage.help(1) + self.usage.help_short(1) def remove(self) -> None: command = Argparse.remove.__name__ @@ -575,7 +578,7 @@ class Argparse(Configs): remove = RemovePackages(packages, self.flags, self.file_pattern) remove.remove() raise SystemExit() - self.usage.help(1) + self.usage.help_short(1) def find(self) -> None: command = Argparse.find.__name__ @@ -592,7 +595,7 @@ class Argparse(Configs): find = FindInstalled() find.find(packages, self.file_pattern) raise SystemExit() - self.usage.help(1) + self.usage.help_short(1) def view(self) -> None: command = Argparse.view.__name__ @@ -610,7 +613,7 @@ class Argparse(Configs): view = ViewPackage(self.flags) view.package(packages) raise SystemExit() - self.usage.help(1) + self.usage.help_short(1) def search(self) -> None: command = Argparse.search.__name__ @@ -627,7 +630,7 @@ class Argparse(Configs): search = SearchPackage() search.package(packages) raise SystemExit() - self.usage.help(1) + self.usage.help_short(1) def dependees(self) -> None: command = Argparse.dependees.__name__ @@ -645,7 +648,7 @@ class Argparse(Configs): dependees = Dependees(packages, self.flags) dependees.slackbuilds() raise SystemExit() - self.usage.help(1) + self.usage.help_short(1) def tracking(self) -> None: command = Argparse.tracking.__name__ @@ -663,7 +666,7 @@ class Argparse(Configs): tracking = Tracking(self.flags) tracking.packages(packages) raise SystemExit() - self.usage.help(1) + self.usage.help_short(1) def help_for_commands(self) -> None: """ Extra help information for commands. """ @@ -671,7 +674,7 @@ class Argparse(Configs): flags = self.commands[self.args[1]] Help(self.args[1], flags).view() else: - self.usage.help_short() + self.usage.help_short(1) def main(): @@ -724,7 +727,7 @@ def main(): try: arguments[args[0]]() except (KeyError, IndexError): - usage.help_short() + usage.help_short(1) if __name__ == '__main__': diff --git a/slpkg/views/cli_menu.py b/slpkg/views/cli_menu.py index 4a5a456e..94f9ce01 100644 --- a/slpkg/views/cli_menu.py +++ b/slpkg/views/cli_menu.py @@ -27,7 +27,7 @@ class Usage(Configs): print(args) raise SystemExit(1) - def help_short(self) -> NoReturn: + def help_short(self, status: int) -> NoReturn: """ Prints the short menu. """ args = ( f'Usage: {self.prog_name} [{self.yellow}OPTIONS{self.endc}] [{self.cyan}COMMAND{self.endc}] ' @@ -45,7 +45,7 @@ class Usage(Configs): " \nIf you need more information please try 'slpkg --help'.") print(args) - raise SystemExit() + raise SystemExit(status) def help(self, status: int) -> NoReturn: """ Prints the main menu. """