From f09745462dfc312f9e9b41fec7f7daf0dc924faf Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Sun, 26 Feb 2023 22:49:03 +0200 Subject: [PATCH] Added help command --- ChangeLog.txt | 1 + slpkg/main.py | 11 +++++++ slpkg/views/cli_menu.py | 6 ++-- slpkg/views/help_commands.py | 59 ++++++++++++++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 slpkg/views/help_commands.py diff --git a/ChangeLog.txt b/ChangeLog.txt index 1ae889a9..660180e2 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -3,6 +3,7 @@ Updated: - Message for configs Added: - For concatenating the short options (Thanks to marav) +- Help command for extra helping 4.5.3 - 27/01/2023 Added: diff --git a/slpkg/main.py b/slpkg/main.py index 11b7596a..bb8c17c2 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -18,6 +18,7 @@ from slpkg.views.version import Version from slpkg.download_only import Download from slpkg.slackbuild import Slackbuilds from slpkg.form_configs import FormConfigs +from slpkg.views.help_commands import Help from slpkg.check_updates import CheckUpdates from slpkg.find_installed import FindInstalled from slpkg.views.view_package import ViewPackage @@ -97,6 +98,7 @@ class Argparse(Configs): self.commands = { '--help': [], '--version': [], + 'help': [], 'update': [ self.flag_yes, self.flag_short_yes, @@ -570,6 +572,14 @@ class Argparse(Configs): raise SystemExit() self.usage.help(1) + def help_for_commands(self): + """ Extra help information for commands. """ + if len(self.args) == 2: + flags = self.commands[self.args[1]] + Help(self.args[1], flags).view() + else: + self.usage.help(1) + def main(): args = sys.argv @@ -582,6 +592,7 @@ def main(): '--help': argparse.help, '-v': argparse.version, '--version': argparse.version, + 'help': argparse.help_for_commands, 'update': argparse.update, '-u': argparse.update, 'upgrade': argparse.upgrade, diff --git a/slpkg/views/cli_menu.py b/slpkg/views/cli_menu.py index b20cceb7..7349eda4 100644 --- a/slpkg/views/cli_menu.py +++ b/slpkg/views/cli_menu.py @@ -70,9 +70,9 @@ class Usage(Configs): f' {self.yellow}-F, --file-pattern={self.endc}PATTERN Include specific installed files.\n' '\n -h, --help Show this message and exit.\n' ' -v, --version Print version and exit.\n' - '\nEdit the configuration file in the /etc/slpkg/slpkg.toml \n' - "or run 'slpkg configs'.\n" - 'If you need more information try to use slpkg manpage.') + "\nConfiguration file in the /etc/slpkg/slpkg.toml or `slpkg configs`.\n" + "If you need more information try to use slpkg manpage.\n" + "Extra help for the commands use: `slpkg help `.") print(args) raise SystemExit(status) diff --git a/slpkg/views/help_commands.py b/slpkg/views/help_commands.py new file mode 100644 index 00000000..9cd4dbb3 --- /dev/null +++ b/slpkg/views/help_commands.py @@ -0,0 +1,59 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- + +from slpkg.configs import Configs + + +class Help(Configs): + + def __init__(self, command, flags): + super(Configs, self).__init__() + self.command = command + self.flags = flags + + color = self.colour() + + self.bold = color['bold'] + self.green = color['green'] + self.cyan = color['cyan'] + self.yellow = color['yellow'] + self.endc = color['endc'] + + def view(self): + help_commands = { + 'update': "Updates the package list and the database.", + 'upgrade': "Upgrade all the installed packages if the newer version exists in the repository.", + 'check-updates': "Check if there is any news on the SlackBuild's ChangeLog.txt file.", + 'configs': "Edit the configuration /etc/slpkg/slpkg.toml file.", + 'clean-logs': "Cleans dependencies log tracking. After that procedure you should remove dependencies by hand.", + 'clean-tmp': "Deletes all the downloaded SlackBuilds scripts and sources.", + 'build': "Builds the Slackbuilds scripts and adds them to the /tmp directory.", + 'install': "Builds and installs the packages in the correct order, and also logs the packages with the dependencies for removal.", + 'download': "Download the SlackBuilds scripts and the sources without building or installing it.", + 'remove': "Removes packages with dependencies if the packages was installed with 'slpkg install' method. Slpkg looks at the 'sbo_repo_tag' configuration to find packages for removal by default, except if you are using '--file-pattern=' option.", + 'find': "Find your installed packages on your system.", + 'view': "View information packages from the repository and get everything in your terminal.", + 'search': "Search and match packages from the repository.", + 'dependees': "Show which SlackBuilds depend on.", + 'tracking': "Tracking the packages dependencies." + } + + help_commands['-u'] = help_commands['update'] + help_commands['-U'] = help_commands['upgrade'] + help_commands['-c'] = help_commands['check-updates'] + help_commands['-g'] = help_commands['configs'] + help_commands['-L'] = help_commands['clean-logs'] + help_commands['-D'] = help_commands['clean-tmp'] + help_commands['-b'] = help_commands['build'] + help_commands['-i'] = help_commands['install'] + help_commands['-d'] = help_commands['download'] + help_commands['-r'] = help_commands['remove'] + help_commands['-f'] = help_commands['find'] + help_commands['-w'] = help_commands['view'] + help_commands['-s'] = help_commands['search'] + help_commands['-e'] = help_commands['dependees'] + help_commands['-t'] = help_commands['tracking'] + + print(f"{self.bold}COMMAND{self.endc}: {self.cyan}{self.command}{self.endc}") + print(f"{self.bold}OPTIONS:{self.endc} {self.yellow}{', '.join(self.flags)}{self.endc}\n") + print(f'{self.bold}{self.green}Help: {self.endc}{help_commands[self.command]}\n')