Improved command handling

This commit is contained in:
2021-03-04 19:06:53 +01:00
parent 2c43e55f77
commit 700bf9c937
17 changed files with 197 additions and 19 deletions

View File

View File

@@ -0,0 +1,13 @@
from cpl_cli.command_abc import CommandABC
from cpl_cli.publish.publisher_abc import PublisherABC
class Build(CommandABC):
def __init__(self, publisher: PublisherABC):
CommandABC.__init__(self)
self._publisher = publisher
def run(self, args: list[str]):
self._publisher.build()

View File

View File

@@ -0,0 +1,28 @@
from cpl.console.console import Console
from cpl_cli.command_abc import CommandABC
class Help(CommandABC):
def __init__(self):
CommandABC.__init__(self)
def run(self, args: list[str]):
Console.write_line('Available Commands:')
commands = [
['build (-b|-B)', 'Prepares files for publish into an output directory named dist/ at the given output path. Must be executed from within a workspace directory.'],
['generate (-g|-G)', 'Generate a new file.'],
['help (-h|-H)', 'Lists available command and their short descriptions.'],
['new (-n|-N)', 'Creates new CPL project.'],
['start (-s|-S)', 'Starts CPL project, restarting on file changes'],
['publish (-p|-P)', 'Prepares files for publish into an output directory named dist/ at the given output path and executes setup.py. Must be executed from within a workspace directory.'],
['update (-u|-u)', 'Update CPL and project dependencies.'],
['version (-v|-V)', '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}')
Console.write('\n')

View File

View File

View File

View File

View File

@@ -0,0 +1,43 @@
import os
import pkgutil
import sys
import platform
import pkg_resources
import cpl
import cpl_cli
from cpl.console.console import Console
from cpl_cli.command_abc import CommandABC
class Version(CommandABC):
def __init__(self):
CommandABC.__init__(self)
def run(self, args: list[str]):
Console.set_foreground_color('yellow')
Console.banner('CPL CLI')
Console.set_foreground_color('default')
if '__version__' in dir(cpl_cli):
Console.write_line(f'Common Python Library CLI: {cpl_cli.__version__}')
Console.write_line(f'Python: {sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}')
Console.write_line(f'OS: {platform.system()} {platform.processor()}')
Console.write_line('CPL:')
packages = []
for importer, modname, is_pkg in pkgutil.iter_modules(cpl.__path__):
module = importer.find_module(modname).load_module(modname)
if '__version__' in dir(module):
packages.append([f'{modname}', module.__version__])
Console.table(['Name', 'Version'], packages)
Console.write_line('\nPython Packages:')
packages = []
dependencies = dict(tuple(str(ws).split()) for ws in pkg_resources.working_set)
for p in dependencies:
packages.append([p, dependencies[p]])
Console.table(['Name', 'Version'], packages)