Mercurial > piecrust2
diff piecrust/main.py @ 466:456db44dcc53
bake: Pass the config variants and values from the CLI to the baker.
TODO: add support for that for the processor pipeline.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sat, 11 Jul 2015 23:51:02 -0700 |
parents | d241585412ad |
children | a8028bf329a2 |
line wrap: on
line diff
--- a/piecrust/main.py Sat Jul 11 20:33:55 2015 -0700 +++ b/piecrust/main.py Sat Jul 11 23:51:02 2015 -0700 @@ -6,7 +6,8 @@ import argparse import colorama from piecrust import APP_VERSION -from piecrust.app import PieCrust, PieCrustConfiguration +from piecrust.app import ( + PieCrust, PieCrustConfiguration, apply_variant_and_values) from piecrust.chefutil import ( format_timed, log_friendly_exception, print_help_item) from piecrust.commands.base import CommandContext @@ -184,15 +185,16 @@ # Build a hash for a custom cache directory. cache_key = 'default' - # Handle a configuration variant. + # Handle custom configurations. + if pre_args.config_variant is not None and not root: + raise SiteNotFoundError("Can't apply any variant.") + apply_variant_and_values(pre_args.config_variant, + pre_args.config_values) + + # Adjust the cache key. if pre_args.config_variant is not None: - if not root: - raise SiteNotFoundError("Can't apply any variant.") - app.config.applyVariant('variants/' + pre_args.config_variant) cache_key += ',variant=%s' % pre_args.config_variant for name, value in pre_args.config_values: - logger.debug("Setting configuration '%s' to: %s" % (name, value)) - app.config.set(name, value) cache_key += ',%s=%s' % (name, value) # Setup the arg parser. @@ -265,6 +267,9 @@ # Run the command! ctx = CommandContext(app, parser, result) + ctx.config_variant = pre_args.config_variant + ctx.config_values = pre_args.config_values + exit_code = result.func(ctx) if exit_code is None: return 0