# HG changeset patch # User Ludovic Chabant # Date 1420182115 28800 # Node ID 8355eb9dd8fe993b0bf12ac742fdf66a5d33b6fa # Parent 4534ccbdd2a3e1fe2184d720fbf1bdc82dc06a6a prepare: Show a more friendly user message when no arguments are given. cosmetic: pep8 compliance. diff -r 4534ccbdd2a3 -r 8355eb9dd8fe piecrust/commands/builtin/scaffolding.py --- a/piecrust/commands/builtin/scaffolding.py Thu Jan 01 21:34:06 2015 -0800 +++ b/piecrust/commands/builtin/scaffolding.py Thu Jan 01 23:01:55 2015 -0800 @@ -46,7 +46,8 @@ continue p = subparsers.add_parser( src.item_name, - help="Creates an empty page in the '%s' source." % src.name) + help=("Creates an empty page in the '%s' source." % + src.name)) src.setupPrepareParser(p, app) p.add_argument('-t', '--template', default='default', help="The template to use, which will change the " @@ -54,6 +55,10 @@ p.set_defaults(source=src) def run(self, ctx): + if not hasattr(ctx.args, 'source'): + raise Exception("No source specified. " + "Please run `chef prepare -h` for usage.") + app = ctx.app source = ctx.args.source metadata = source.buildMetadata(ctx.args) @@ -61,7 +66,8 @@ path = source.resolveRef(rel_path) name, ext = os.path.splitext(path) if ext == '.*': - path = '%s.%s' % (name, + path = '%s.%s' % ( + name, app.config.get('site/default_auto_format')) if os.path.exists(path): raise Exception("'%s' already exists." % path) @@ -78,7 +84,7 @@ tpl_text = ext.getTemplate(ctx.app, tpl_name) title = (metadata.get('slug') or metadata.get('path') or - 'Untitled page') + 'Untitled page') title = make_title(title) tokens = { '%title%': title, @@ -126,7 +132,7 @@ def getHelpTopics(self): return [('scaffolding', - "Available templates for the 'prepare' command.")] + "Available templates for the 'prepare' command.")] def getHelpTopic(self, topic, app): with io.StringIO() as tplh: @@ -139,9 +145,10 @@ help_list = tplh.getvalue() help_txt = ( - textwrap.fill("Running the 'prepare' command will let " - "PieCrust setup a page for you in the correct place, with " - "some hopefully useful default text.") + + textwrap.fill( + "Running the 'prepare' command will let " + "PieCrust setup a page for you in the correct place, with " + "some hopefully useful default text.") + "\n\n" + textwrap.fill("The following templates are available:") + "\n\n" +