From 61cc5bbf75c128cf2f4f5ea905a66f618eb64f2e Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Fri, 21 Mar 2014 17:14:21 +0100 Subject: [PATCH] Better verbosity CLI option, no config value --- example.cfg | 1 - vdirsyncer/cli.py | 33 +++++++++++++++++++++++---------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/example.cfg b/example.cfg index 3409f9c..4fd9b93 100644 --- a/example.cfg +++ b/example.cfg @@ -4,7 +4,6 @@ [general] # A folder where vdirsyncer can store some metadata about each pair. status_path = ~/.vdirsyncer/status/ -#verbose = False # setting this to true will show e.g. HTTP traffic # CONTACTS [pair bob_contacts] diff --git a/vdirsyncer/cli.py b/vdirsyncer/cli.py index 622ce26..c33b3fd 100644 --- a/vdirsyncer/cli.py +++ b/vdirsyncer/cli.py @@ -137,14 +137,32 @@ def _main(env, file_cfg): # https://github.com/DasIch/argvard/issues/2 app.options['--help'].function(context) - @app.option('--verbose|-v') - def verbose_option(context=None): - '''Print more information.''' - log.set_level(log.logging.DEBUG) + @app.option('--verbosity verbosity') + def verbose_option(context, verbosity): + ''' + Basically Python logging levels. + + CRITICAL: Config errors, at most. + + ERROR: Normal errors, at most. + + WARNING: Problems of which vdirsyncer thinks that it can handle them + itself, but which might crash other clients. + + INFO: Normal output. + + DEBUG: Show e.g. HTTP traffic. Not supposed to be readable by the + normal user. + + ''' + x = getattr(log.logging, verbosity, None) + if x is None: + raise ValueError(u'Invalid verbosity value: {}'.format(verbosity)) + log.set_level(x) @app.option('--quiet|-q') def quiet_option(context=None): - '''Inverse of --verbose.''' + '''Print less information than normal.''' log.set_level(log.logging.WARNING) sync_command = argvard.Command() @@ -190,9 +208,4 @@ def _main(env, file_cfg): action() app.register_command('sync', sync_command) - - if general.get('verbose', False): - verbose_option() - else: - quiet_option() app()