Skip to content

Commit d5d76a8

Browse files
authored
Keep logging verbosity and output format on namespace. (#109)
1 parent e3ba37f commit d5d76a8

File tree

4 files changed

+2
-23
lines changed

4 files changed

+2
-23
lines changed

knack/log.py

+1-14
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from logging.handlers import RotatingFileHandler
99

1010
from .util import CtxTypeError, ensure_dir
11-
from .events import EVENT_INVOKER_PRE_CMD_TBL_CREATE, EVENT_PARSER_GLOBAL_CREATE
11+
from .events import EVENT_PARSER_GLOBAL_CREATE
1212

1313
CLI_LOGGER_NAME = 'cli'
1414

@@ -98,18 +98,6 @@ def on_global_arguments(_, **kwargs):
9898
arg_group.add_argument(CLILogging.DEBUG_FLAG, dest='_log_verbosity_debug', action='store_true',
9999
help='Increase logging verbosity to show all debug logs.')
100100

101-
@staticmethod
102-
def remove_logger_flags(_, **kwargs):
103-
args = kwargs.get('args')
104-
try:
105-
args.remove(CLILogging.VERBOSE_FLAG)
106-
except ValueError:
107-
pass
108-
try:
109-
args.remove(CLILogging.DEBUG_FLAG)
110-
except ValueError:
111-
pass
112-
113101
def __init__(self, name, cli_ctx=None):
114102
"""
115103
@@ -128,7 +116,6 @@ def __init__(self, name, cli_ctx=None):
128116
self.console_log_format = CLILogging._get_console_log_format()
129117
self.cli_ctx = cli_ctx
130118
self.cli_ctx.register_event(EVENT_PARSER_GLOBAL_CREATE, CLILogging.on_global_arguments)
131-
self.cli_ctx.register_event(EVENT_INVOKER_PRE_CMD_TBL_CREATE, CLILogging.remove_logger_flags)
132119

133120
def configure(self, args):
134121
""" Configure the loggers with the appropriate log level etc.

knack/output.py

-2
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ def handle_output_argument(cli_ctx, **kwargs):
9696
args = kwargs.get('args')
9797
# Set the output type for this invocation
9898
cli_ctx.invocation.data['output'] = getattr(args, OutputProducer.ARG_DEST)
99-
# We've handled the argument so remove it
100-
delattr(args, OutputProducer.ARG_DEST)
10199

102100
def __init__(self, cli_ctx=None):
103101
""" Manages the production of output from the result of a command invocation

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from codecs import open
1010
from setuptools import setup, find_packages
1111

12-
VERSION = '0.4.4'
12+
VERSION = '0.4.5'
1313

1414
DEPENDENCIES = [
1515
'argcomplete',

tests/test_log.py

-6
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@ def test_logging_argument_registrations(self):
3030
parser_arg_group_mock.add_argument.assert_any_call(CLILogging.DEBUG_FLAG, dest=mock.ANY, action=mock.ANY,
3131
help=mock.ANY)
3232

33-
def test_logging_arguments_removed(self):
34-
arguments = [CLILogging.VERBOSE_FLAG, CLILogging.DEBUG_FLAG]
35-
self.mock_ctx.raise_event(EVENT_INVOKER_PRE_CMD_TBL_CREATE, args=arguments)
36-
# After the event is raised, the arguments should have been removed
37-
self.assertFalse(arguments)
38-
3933

4034
class TestLoggingLevel(unittest.TestCase):
4135
def setUp(self):

0 commit comments

Comments
 (0)