From 082c5f220cb09dc0ded9fc0218e18b174d5a04dc Mon Sep 17 00:00:00 2001 From: ldericher Date: Thu, 13 Aug 2020 11:32:54 +0200 Subject: [PATCH] ProjectCommand, ServiceCommand aux classes --- src/kiwi/subcommands/_subcommand.py | 30 +++++++++++++++++++++++++++++ src/kiwi/subcommands/logs.py | 15 +++------------ 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/kiwi/subcommands/_subcommand.py b/src/kiwi/subcommands/_subcommand.py index ef3833f..cd84a26 100644 --- a/src/kiwi/subcommands/_subcommand.py +++ b/src/kiwi/subcommands/_subcommand.py @@ -23,3 +23,33 @@ class SubCommand: def run(self, config, args): """actually run command with this dir's config and parsed CLI args""" pass + + +class ProjectCommand(SubCommand): + """this command concerns a project in current instance""" + + def __init__(self, name, **kwargs): + super().__init__( + name, + **kwargs + ) + + self._sub_parser.add_argument( + 'project', type=str, + help="select a project in this instance" + ) + + +class ServiceCommand(ProjectCommand): + """this command concerns services in a project""" + + def __init__(self, name, **kwargs): + super().__init__( + name, + **kwargs + ) + + self._sub_parser.add_argument( + 'services', metavar='service', nargs='*', type=str, + help="select service(s) in a project" + ) diff --git a/src/kiwi/subcommands/logs.py b/src/kiwi/subcommands/logs.py index 1928233..abcf354 100644 --- a/src/kiwi/subcommands/logs.py +++ b/src/kiwi/subcommands/logs.py @@ -2,32 +2,23 @@ import logging # local -from ._subcommand import SubCommand +from ._subcommand import ServiceCommand from .utils.dockercommand import DockerCommand -class LogsCommand(SubCommand): +class LogsCommand(ServiceCommand): def __init__(self): super().__init__( 'logs', description="Show logs of a project or service(s) of a project" ) + # -f switch: Follow logs self._sub_parser.add_argument( '-f', '--follow', action='store_true', help="output appended data as log grows" ) - self._sub_parser.add_argument( - 'project', type=str, - help="select a project in this instance" - ) - - self._sub_parser.add_argument( - 'services', metavar='service', nargs='*', type=str, - help="select service(s) in a project" - ) - def run(self, config, args): project_name = args.project project_marker = config['markers:project']