From acfe158470661db43375c87cde5f2096cc3a1d0c Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Wed, 16 Dec 2020 15:09:12 +0100 Subject: [PATCH] Improved version command & improved help command --- src/sh_edraft/cli/cpl_cli/commands/help.py | 10 ++++++++++ src/sh_edraft/cli/cpl_cli/commands/version.py | 12 +++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/sh_edraft/cli/cpl_cli/commands/help.py b/src/sh_edraft/cli/cpl_cli/commands/help.py index 21885eb1..7999bdb0 100644 --- a/src/sh_edraft/cli/cpl_cli/commands/help.py +++ b/src/sh_edraft/cli/cpl_cli/commands/help.py @@ -9,3 +9,13 @@ class Help(CommandBase): def run(self, args: list[str]): Console.write_line('Available Commands:') + commands = [ + ['help', 'Lists available commands and their short descriptions.'], + ['new', 'Creates a new file or package.'], + ['version', 'Outputs CPL CLI version.'] + ] + for name, description in commands: + Console.set_foreground_color('blue') + Console.write(f'\n\t{name} ') + Console.set_foreground_color('default') + Console.write(f'{description}') diff --git a/src/sh_edraft/cli/cpl_cli/commands/version.py b/src/sh_edraft/cli/cpl_cli/commands/version.py index 0f7a4a47..e514101f 100644 --- a/src/sh_edraft/cli/cpl_cli/commands/version.py +++ b/src/sh_edraft/cli/cpl_cli/commands/version.py @@ -2,6 +2,8 @@ import pkgutil import sys import platform +import pkg_resources + import sh_edraft from sh_edraft import cli from sh_edraft.cli.command.base.command_base import CommandBase @@ -25,6 +27,14 @@ class Version(CommandBase): packages = [] for importer, modname, is_pkg in pkgutil.iter_modules(sh_edraft.__path__): module = importer.find_module(modname).load_module(modname) - packages.append([f'{modname}:', module.__version__]) + packages.append([f'{modname}', module.__version__]) + + Console.table(['Name', 'Version'], packages) + + Console.write_line('\nPython Packages:') + packages = [] + deps = dict(tuple(str(ws).split()) for ws in pkg_resources.working_set) + for p in deps: + packages.append([p, deps[p]]) Console.table(['Name', 'Version'], packages)