From 80181505a2e3c166c43e033bb06b0a423cb9da3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Thu, 20 Jan 2022 10:55:47 +0100 Subject: [PATCH] kiwi_help display --- kiwi_scp/commands/cli.py | 33 ++++++++++++++++++++++++++++++ kiwi_scp/data/etc/command_help.txt | 22 -------------------- kiwi_scp/data/etc/kiwi_help.txt | 9 -------- kiwi_scp/scripts/kiwi.py | 10 ++++++++- 4 files changed, 42 insertions(+), 32 deletions(-) delete mode 100644 kiwi_scp/data/etc/command_help.txt delete mode 100644 kiwi_scp/data/etc/kiwi_help.txt diff --git a/kiwi_scp/commands/cli.py b/kiwi_scp/commands/cli.py index 88812d3..74c947d 100644 --- a/kiwi_scp/commands/cli.py +++ b/kiwi_scp/commands/cli.py @@ -1,5 +1,6 @@ import importlib import os +from gettext import gettext as _ from typing import List, Optional import click @@ -39,3 +40,35 @@ class KiwiCLI(click.MultiCommand): else: raise Exception("Fail member name") + + def format_commands(self, ctx: click.Context, formatter: click.HelpFormatter) -> None: + commands = { + "Operation": [ + "up", "down", "restart", "update", + ], + "Instance Management": [ + "init", "list", + ], + "Project and Service Management": [ + "new", "enable", "disable", "logs", "shell", "cmd", + ], + "Image Handling": [ + "build", "pull", "push", + ], + } + + # allow for 3 times the default spacing + cmd_names = set(self.list_commands(ctx)) + limit = formatter.width - 6 - max(len(cmd_name) for cmd_name in cmd_names) + + for purpose, cmd_list in commands.items(): + with formatter.section(_(f"Commands for {purpose}")): + formatter.write_dl([ + (cmd_name, self.get_command(ctx, cmd_name).get_short_help_str(limit)) + for cmd_name in cmd_list + ]) + + cmd_names -= set(cmd_list) + + if len(cmd_names) > 0: + raise Exception(f"Some commands were not registered in a group above: {cmd_names}") diff --git a/kiwi_scp/data/etc/command_help.txt b/kiwi_scp/data/etc/command_help.txt deleted file mode 100644 index 33c0376..0000000 --- a/kiwi_scp/data/etc/command_help.txt +++ /dev/null @@ -1,22 +0,0 @@ -Commands for Operation: - up Bring up the whole instance, a project or service(s) inside a project - down Bring down the whole instance, a project or service(s) inside a project - update Update the whole instance, a project or service(s) inside a project - restart Restart the whole instance, a project or service(s) inside a project - -Commands for Instance Management: - init Initialize or reconfigure kiwi-scp instance - show Show projects in this instance, services inside a project or service(s) inside a project - cmd Run raw docker-compose command in a project - -Commands for Project and Service Management: - new Create new empty project(s) in this instance - enable Enable project(s) in this instance - disable Disable project(s) in this instance - logs Show logs of a project or service(s) inside a project - shell Spawn shell inside a service inside a project - -Commands for Image Handling: - build Build images for the whole instance, a project or service(s) inside a project - pull Pull images for the whole instance, a project or service(s) inside a project - push Push images for the whole instance, a project or service(s) inside a project \ No newline at end of file diff --git a/kiwi_scp/data/etc/kiwi_help.txt b/kiwi_scp/data/etc/kiwi_help.txt deleted file mode 100644 index 08d0224..0000000 --- a/kiwi_scp/data/etc/kiwi_help.txt +++ /dev/null @@ -1,9 +0,0 @@ -kiwi is the simple tool for managing container servers. - -Features: - - Group services into projects using their own docker-compose.yml - - Bind to the local file system by using ${TARGETDIR} as volume in docker-compose.yml - - Add instance-global config files by using ${CONFDIR} as volume in docker-compose.yml - - Add instance-global custom values inside docker-compose.yml using config:runtime:env - - Build service-specific, private docker images from Dockerfiles - - Check full instances into any version control system diff --git a/kiwi_scp/scripts/kiwi.py b/kiwi_scp/scripts/kiwi.py index f408986..4b00c07 100644 --- a/kiwi_scp/scripts/kiwi.py +++ b/kiwi_scp/scripts/kiwi.py @@ -12,7 +12,15 @@ from kiwi_scp.commands import KiwiCLI ) @click.command(cls=KiwiCLI) def main(verbose: int) -> None: - """kiwi is the simple tool for managing container servers.""" + """kiwi is the simple tool for managing container servers. + + \b + - Manage full instances using just your favorite version control system + - Group services into projects, each with their own docker-compose.yml + - Build service-specific, private docker images from Dockerfiles + - Make use of the local file system by referring to ${TARGETDIR}, ${TARGETROOT} and ${CONFDIR} in compose files + - Create your own instance-global variables for compose files using the kiwi.yml "environment" section + """ if verbose >= 2: log_level = logging.DEBUG