diff options
author | Taseer Ahmed <taseer94@gmail.com> | 2017-03-04 12:52:50 +0500 |
---|---|---|
committer | Taseer Ahmed <taseer94@gmail.com> | 2017-03-04 13:14:38 +0500 |
commit | 17c1050f26d6b1693e9731253d8f297aed99fee5 (patch) | |
tree | 0a885de58c4b68c6deed731680c583073da45a4b | |
parent | 26dc128e571e38d5264b2708001f1d63e4cd6d52 (diff) |
Implement debug option
Show traceback only when debug flag specified.
JIRA: QTIP-201
Change-Id: I9cc4b4ed5a2cb2d2efabd9c0eb3aac216321ebac
Signed-off-by: Taseer Ahmed <taseer94@gmail.com>
-rw-r--r-- | qtip/cli/entry.py | 29 | ||||
-rw-r--r-- | tests/unit/cli/options_test.py | 9 |
2 files changed, 13 insertions, 25 deletions
diff --git a/qtip/cli/entry.py b/qtip/cli/entry.py index 9f51f25e..6cf78b58 100644 --- a/qtip/cli/entry.py +++ b/qtip/cli/entry.py @@ -1,5 +1,5 @@ ############################################################################## -# Copyright (c) 2016 ZTE Corp and others. +# Copyright (c) 2017 taseer94@gmail.com and others. # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Apache License, Version 2.0 @@ -7,33 +7,19 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +import click import os import sys -import click CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help']) +# TODO (taseer) define user friendly error messages +sys.tracebacklimit = 0 -class Context(object): - - ''' TODO(taseer) implementation''' - - def __init__(self): - self.verbose = False - self.debug = False - - def log(self, msg, *args): - ''' Log message to stderr ''' - pass - def verbose(self, msg, *args): - ''' Log message to stderr when verbose ''' - pass - - def debug(self, msg, *args): - ''' Log message to debug ''' - pass +class Context(object): + """ Load configuration and pass to subcommands """ pass_context = click.make_pass_decorator(Context, ensure=True) @@ -70,4 +56,5 @@ class QtipCli(click.MultiCommand): @click.version_option('dev') @pass_context def cli(ctx, verbose, debug): - pass + if debug: + sys.tracebacklimit = 8 diff --git a/tests/unit/cli/options_test.py b/tests/unit/cli/options_test.py index f9472814..9dbbe6f3 100644 --- a/tests/unit/cli/options_test.py +++ b/tests/unit/cli/options_test.py @@ -1,5 +1,5 @@ ############################################################### -# Copyright (c) 2016 ZTE Corp and others. +# Copyright (c) 2017 taseer94@gmail.com and others. # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Apache License, Version 2.0 @@ -8,8 +8,9 @@ ############################################################################## import pytest -from click.testing import CliRunner +import sys +from click.testing import CliRunner from qtip.cli.entry import cli @@ -28,5 +29,5 @@ class TestClass(object): assert 'dev' in result.output def test_debug(self, runner): - result = runner.invoke(cli, ['-d']) - assert '' in result.output + runner.invoke(cli, ['-d']) + assert sys.tracebacklimit == 8 |