Commit 596997be authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Move default argument initilization to kamaki.cli

Default arguments where set in kamaki.cli.arguments using the
global variable "_arguments". This was a semantic mistake, a
pep8 violation and arguably bad style.  The "_config_arg"
variable was also global and auxiliary to "_arguments"

The "_argument" and "_config_arg" global vars are removed from
kamaki.cli.arguments. The initialization is now an internal
proccess in the "main" function of kamaki.cli, which is the
method responsible for setting up all kamaki interfaces.
parent a14586a8
......@@ -36,7 +36,9 @@ from sys import argv, exit, stdout, stderr
from os.path import basename, exists
from inspect import getargspec
from kamaki.cli.argument import ArgumentParseManager
from kamaki.cli.argument import (
ArgumentParseManager, ConfigArgument, ValueArgument, FlagArgument,
RuntimeConfigArgument, VersionArgument, Argument)
from kamaki.cli.history import History
from kamaki.cli.utils import print_dict, red, magenta, yellow, pref_enc
from kamaki.cli.errors import CLIError, CLICmdSpecError
......@@ -175,13 +177,9 @@ cmd_spec_locations = [
# Generic init auxiliary functions
def _setup_logging(silent=False, debug=False, verbose=False):
def _setup_logging(debug=False, verbose=False):
"""handle logging for clients package"""
if silent:
logger.add_stream_logger(__name__, logging.CRITICAL)
sfmt, rfmt = '> %(message)s', '< %(message)s'
if debug:
print('Logging location: %s' % logger.get_log_filename())
......@@ -238,8 +236,7 @@ def _init_session(arguments, is_non_API=False):
_verbose = arguments['verbose'].value
_cnf = arguments['config']
_silent = arguments['silent'].value
_setup_logging(_silent, _debug, _verbose)
_setup_logging(_debug, _verbose)
if _help or is_non_API:
return None
......@@ -506,8 +503,22 @@ def main(func):
for arg in reversed(internal_argv):
argv.insert(0, arg)
parser = ArgumentParseManager(exe)
_config_arg = ConfigArgument('Path to config file')
parser = ArgumentParseManager(exe, arguments=dict(
'Chose a cloud to connect to', ('--cloud')),
help=Argument(0, 'Show help message', ('-h', '--help')),
debug=FlagArgument('Include debug output', ('-d', '--debug')),
'More info at response', ('-v', '--verbose')),
'Print current version', ('-V', '--version')),
'Override a config value', ('-o', '--options')))
if parser.arguments['version'].value:
......@@ -181,9 +181,6 @@ class ConfigArgument(Argument):
return self.value.get_cloud(cloud, option)
_config_arg = ConfigArgument('Path to config file')
class RuntimeConfigArgument(Argument):
"""Set a run-time setting option (not persistent)"""
......@@ -549,21 +546,6 @@ class ProgressBarArgument(FlagArgument):
_arguments = dict(
cloud=ValueArgument('Chose a cloud to connect to', ('--cloud')),
help=Argument(0, 'Show help message', ('-h', '--help')),
debug=FlagArgument('Include debug output', ('-d', '--debug')),
# 'Include raw connection data in the output', ('-i', '--include')),
silent=FlagArgument('Do not output anything', ('-s', '--silent')),
verbose=FlagArgument('More info at response', ('-v', '--verbose')),
version=VersionArgument('Print current version', ('-V', '--version')),
_config_arg, 'Override a config value', ('-o', '--options'))
# Initial command line interface arguments
......@@ -571,9 +553,8 @@ class ArgumentParseManager(object):
"""Manage (initialize and update) an ArgumentParser object"""
def __init__(
self, exe,
arguments=None, required=None, syntax=None, description=None,
self, exe, arguments,
required=None, syntax=None, description=None, check_required=True):
:param exe: (str) the basic command (e.g. 'kamaki')
......@@ -604,11 +585,7 @@ class ArgumentParseManager(object):
'%s <cmd_group> [<cmd_subbroup> ...] <cmd>' % exe)
self.required, self.check_required = required, check_required
self.parser.description = description or ''
if arguments:
self.arguments = arguments
global _arguments
self.arguments = _arguments
self.arguments = arguments
self._parser_modified, self._parsed, self._unparsed = False, None, None
......@@ -173,7 +173,6 @@ class Shell(Cmd):
tmp_args.pop('cloud', None)
tmp_args.pop('debug', None)
tmp_args.pop('verbose', None)
tmp_args.pop('silent', None)
tmp_args.pop('config', None)
help_parser = ArgumentParseManager(
cmd_name, tmp_args, required,
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