Commit 535bc83e authored by Marco Mariani's avatar Marco Mariani

provide -h by default; handle multiline help; multiple verbose levels

parent 836dc719
# -*- coding: utf-8 -*-
import argparse
import cliff
class Command(cliff.command.Command):
def get_parser(self, prog_name):
parser = argparse.ArgumentParser(
description=self.get_description(),
prog=prog_name,
formatter_class=argparse.RawTextHelpFormatter
)
return parser
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
import ConfigParser import ConfigParser
import os import os
from cliff.command import Command from slapos.cli.command import Command
class ConfigError(Exception): class ConfigError(Exception):
......
...@@ -22,6 +22,14 @@ class SlapOSCommandManager(cliff.commandmanager.CommandManager): ...@@ -22,6 +22,14 @@ class SlapOSCommandManager(cliff.commandmanager.CommandManager):
class SlapOSApp(cliff.app.App): class SlapOSApp(cliff.app.App):
#
# self.options.verbose_level:
# -q -> 0
# -v -> 2
# -vv -> 3
# etc.
#
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
def __init__(self): def __init__(self):
...@@ -32,19 +40,25 @@ class SlapOSApp(cliff.app.App): ...@@ -32,19 +40,25 @@ class SlapOSApp(cliff.app.App):
) )
def initialize_app(self, argv): def initialize_app(self, argv):
if self.options.verbose_level > 2:
self.log.debug('initialize_app') self.log.debug('initialize_app')
def prepare_to_run_command(self, cmd): def prepare_to_run_command(self, cmd):
if self.options.verbose_level > 2:
self.log.debug('prepare_to_run_command %s', cmd.__class__.__name__) self.log.debug('prepare_to_run_command %s', cmd.__class__.__name__)
def clean_up(self, cmd, result, err): def clean_up(self, cmd, result, err):
if self.options.verbose_level > 2:
self.log.debug('clean_up %s', cmd.__class__.__name__) self.log.debug('clean_up %s', cmd.__class__.__name__)
if err: if err:
self.log.debug('got an error: %s', err) self.log.debug('got an error: %s', err)
def main(argv=sys.argv[1:]): def main(argv=sys.argv[1:]):
app = SlapOSApp() app = SlapOSApp()
if not argv:
argv = ['-h']
return app.run(argv) return app.run(argv)
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
import logging import logging
import sys import sys
from cliff.command import Command from slapos.cli.command import Command
from slapos.register.register import do_register, RegisterConfig from slapos.register.register import do_register, RegisterConfig
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment