Changeset - bc60e907f73d
[Not reviewed]
default
0 1 0
Thomas De Schampheleire - 7 years ago 2018-09-24 22:37:44
thomas.de_schampheleire@nokia.com
make-config: reorganize code to make it clear that --show-defaults can't be combined with custom key=value

The key=value arguments could only be specified after specifying an ini file,
and that couldn't be combined with --show-defaults.
1 file changed with 10 insertions and 14 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/paster_commands/make_config.py
Show inline comments
 
@@ -41,8 +41,8 @@ class Command(BasePasterCommand):
 
    file (possibly filling in defaults from the extra
 
    variables you give).
 

	
 
    The first key=value arguments are used to customize the Mako variables that
 
    are shown with --show-defaults. The following settings will be
 
    The first key=value arguments are used to customize the Mako variables from
 
    what is shown with --show-defaults. Any following key=value arguments will be
 
    patched/inserted in the [app:main] section ... until another section name
 
    is specified and change where the following values go.
 
    """
 
@@ -59,7 +59,7 @@ class Command(BasePasterCommand):
 
            help='application config file to write')
 

	
 
        parser.add_argument('custom', nargs=argparse.REMAINDER,
 
            help='custom values for the config file')
 
            help='"key=value" for customizing the config file')
 

	
 
        parser.add_argument('--show-defaults', action='store_true',
 
            help="Show the default values that can be overridden")
 
@@ -68,12 +68,14 @@ class Command(BasePasterCommand):
 

	
 

	
 
def _run(args):
 
    if args.show_defaults:
 
        if args.config_file is not None:
 
            raise ValueError("Can't specify both config file and --show-defaults")
 
        for key, value in inifile.default_variables.items():
 
            print '%s=%s' % (key, value)
 
        sys.exit(0)
 
    if args.config_file is None:
 
        if not args.show_defaults:
 
            raise ValueError("Missing argument: config_file")
 
    else:
 
        if args.show_defaults:
 
            raise ValueError("Can't specify both config_file and --show_defaults")
 
        raise ValueError("Missing argument: config file")
 

	
 
    mako_variable_values = {}
 
    ini_settings = defaultdict(dict)
 
@@ -94,12 +96,6 @@ def _run(args):
 
        else:
 
            raise ValueError("Invalid name=value parameter %r" % parameter)
 

	
 
    if args.show_defaults:
 
        for key, value in inifile.default_variables.items():
 
            value = mako_variable_values.get(key, value)
 
            print '%s=%s' % (key, value)
 
        sys.exit(0)
 

	
 
    # use default that cannot be replaced
 
    mako_variable_values.update({
 
        'uuid': lambda: uuid.uuid4().hex,
0 comments (0 inline, 0 general)