diff --git a/slpkg/main.py b/slpkg/main.py index 5d6b3eef..e5151625 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -51,11 +51,7 @@ class Argparse: self.flag_full_reverse = '--full-reverse' self.flag_search = '--search' - if (not self.configs.dialog and self.flag_search in self.args or - not self.configs.dialog and 'configs' in self.args): - print("Error: You should enable the dialog " - "in the '/etc/slpkg/' folder.\n") - self.usage.help(1) + self.dialog_is_enabled() self.options = [self.flag_yes, self.flag_jobs, @@ -65,18 +61,31 @@ class Argparse: self.flag_full_reverse, self.flag_search] - # Check for correct flag - for opt in self.args: - if opt.startswith('--'): - if opt not in self.options and opt not in ['--help', '--version']: - raise SystemExit(f"\nError: flag '{opt}' does not exist.\n") + self.check_for_flags() + self.remove_flags() - # Remove flags from args + def remove_flags(self): + """ Remove flags from args. """ for opt in self.options: if opt in self.args: self.args.remove(opt) self.flags.append(opt) + def dialog_is_enabled(self): + """ Checking if the dialog box is enabled. """ + if (not self.configs.dialog and self.flag_search in self.args or + not self.configs.dialog and 'configs' in self.args): + print("Error: You should enable the dialog " + "in the '/etc/slpkg/' folder.\n") + self.usage.help(1) + + def check_for_flags(self): + """ Check for correct flag. """ + for opt in self.args: + if opt.startswith('--'): + if opt not in self.options and opt not in ['--help', '--version']: + raise SystemExit(f"\nError: flag '{opt}' does not exist.\n") + def choose_packages(self, packages, method): """ Choose packages with dialog utility and --search flag. """ height = 10