Improved version command & improved help command

This commit is contained in:
Sven Heidemann 2020-12-16 15:09:12 +01:00
parent 5fb20035d8
commit acfe158470
2 changed files with 21 additions and 1 deletions

View File

@ -9,3 +9,13 @@ class Help(CommandBase):
def run(self, args: list[str]): def run(self, args: list[str]):
Console.write_line('Available Commands:') 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}')

View File

@ -2,6 +2,8 @@ import pkgutil
import sys import sys
import platform import platform
import pkg_resources
import sh_edraft import sh_edraft
from sh_edraft import cli from sh_edraft import cli
from sh_edraft.cli.command.base.command_base import CommandBase from sh_edraft.cli.command.base.command_base import CommandBase
@ -25,6 +27,14 @@ class Version(CommandBase):
packages = [] packages = []
for importer, modname, is_pkg in pkgutil.iter_modules(sh_edraft.__path__): for importer, modname, is_pkg in pkgutil.iter_modules(sh_edraft.__path__):
module = importer.find_module(modname).load_module(modname) 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) Console.table(['Name', 'Version'], packages)