Added help command

This commit is contained in:
Dimitris Zlatanidis 2023-02-26 22:49:03 +02:00
parent d370e2c026
commit f09745462d
4 changed files with 74 additions and 3 deletions

View file

@ -3,6 +3,7 @@ Updated:
- Message for configs - Message for configs
Added: Added:
- For concatenating the short options (Thanks to marav) - For concatenating the short options (Thanks to marav)
- Help command for extra helping
4.5.3 - 27/01/2023 4.5.3 - 27/01/2023
Added: Added:

View file

@ -18,6 +18,7 @@ from slpkg.views.version import Version
from slpkg.download_only import Download from slpkg.download_only import Download
from slpkg.slackbuild import Slackbuilds from slpkg.slackbuild import Slackbuilds
from slpkg.form_configs import FormConfigs from slpkg.form_configs import FormConfigs
from slpkg.views.help_commands import Help
from slpkg.check_updates import CheckUpdates from slpkg.check_updates import CheckUpdates
from slpkg.find_installed import FindInstalled from slpkg.find_installed import FindInstalled
from slpkg.views.view_package import ViewPackage from slpkg.views.view_package import ViewPackage
@ -97,6 +98,7 @@ class Argparse(Configs):
self.commands = { self.commands = {
'--help': [], '--help': [],
'--version': [], '--version': [],
'help': [],
'update': [ 'update': [
self.flag_yes, self.flag_yes,
self.flag_short_yes, self.flag_short_yes,
@ -570,6 +572,14 @@ class Argparse(Configs):
raise SystemExit() raise SystemExit()
self.usage.help(1) 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(): def main():
args = sys.argv args = sys.argv
@ -582,6 +592,7 @@ def main():
'--help': argparse.help, '--help': argparse.help,
'-v': argparse.version, '-v': argparse.version,
'--version': argparse.version, '--version': argparse.version,
'help': argparse.help_for_commands,
'update': argparse.update, 'update': argparse.update,
'-u': argparse.update, '-u': argparse.update,
'upgrade': argparse.upgrade, 'upgrade': argparse.upgrade,

View file

@ -70,9 +70,9 @@ class Usage(Configs):
f' {self.yellow}-F, --file-pattern={self.endc}PATTERN Include specific installed files.\n' f' {self.yellow}-F, --file-pattern={self.endc}PATTERN Include specific installed files.\n'
'\n -h, --help Show this message and exit.\n' '\n -h, --help Show this message and exit.\n'
' -v, --version Print version and exit.\n' ' -v, --version Print version and exit.\n'
'\nEdit the configuration file in the /etc/slpkg/slpkg.toml \n' "\nConfiguration file in the /etc/slpkg/slpkg.toml or `slpkg configs`.\n"
"or run 'slpkg configs'.\n" "If you need more information try to use slpkg manpage.\n"
'If you need more information try to use slpkg manpage.') "Extra help for the commands use: `slpkg help <command>`.")
print(args) print(args)
raise SystemExit(status) raise SystemExit(status)

View file

@ -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')