Repository: Pylons/pyramid

Issue:
Suggestion: pcreate should list the template part of basic usage



Discussion:
@goodwillcoding can you elaborate?

@goodwillcoding do you mean this?

``` bash
$ env27/bin/pcreate -l
Available scaffolds:
  alchemy:  Pyramid SQLAlchemy project using url dispatch
  starter:  Pyramid starter project
  zodb:     Pyramid ZODB project using traversal
```

It would be nice if it listed them when you just call `pcreate` without any arguments.

@bertjwregeer or usage information, a la `pcreate -h`?

When I start a new project using `pcreate` there are three stages before actually creating the project.
1. `pcreate` -- damnit, what are the flags again?
2. `pcreate -h` okay, now what are the scaffolds I have installed?
3. `pcreate -l` Alright, alchemy sounds good
4. `pcreate -s alchemy myproject`

If `pcreate` stand-alone would print the help, AND the list of scaffolds that would stop a few steps.

If it's going to be changed, just have the empty pcreate command default to
say.. "You must provide at least one scaffold name, use "pcreate --help"
for a list of further options".
On 10 Sep 2014 07:35, "Bert JW Regeer" notifications@github.com wrote:

> When I start a new project using pcreate there are three stages before
> actually creating the project.
> 1. pcreate -- damnit, what are the flags again?
> 2. pcreate -h okay, now what are the scaffolds I have installed?
> 3. pcreate -l Alright, alchemy sounds good
> 4. pcreate -s alchemy myproject
> 
> If pcreate stand-alone would print the help, AND the list of scaffolds
> that would stop a few steps.
> 
> —
> Reply to this email directly or view it on GitHub
> https://github.com/Pylons/pyramid/issues/1297#issuecomment-55076499.

@crooksey The default case requires that you provide a scaffold name, having to go to the `--help` to find the `-l` option to figure out what scaffolds exist is an extra step, which should be unnecessary. Also, the scaffold has to be specified by the `-s` option, which is not entirely clear.

I'd give a :+1: to @bertjwregeer 's idea about showing both help and a list when no arguments are sent.


Resolving patch:
diff --git a/pyramid/scripts/pcreate.py b/pyramid/scripts/pcreate.py
--- a/pyramid/scripts/pcreate.py
+++ b/pyramid/scripts/pcreate.py
@@ -18,7 +18,7 @@ def main(argv=sys.argv, quiet=False):
 class PCreateCommand(object):
     verbosity = 1 # required
     description = "Render Pyramid scaffolding to an output directory"
-    usage = "usage: %prog [options] output_directory"
+    usage = "usage: %prog [options] -s <scaffold> output_directory"
     parser = optparse.OptionParser(usage, description=description)
     parser.add_option('-s', '--scaffold',
                       dest='scaffold_name',
@@ -63,8 +63,16 @@ def __init__(self, argv, quiet=False):
     def run(self):
         if self.options.list:
             return self.show_scaffolds()
+        if not self.options.scaffold_name and not self.args:
+            if not self.quiet: # pragma: no cover
+                self.parser.print_help()
+                self.out('')
+                self.show_scaffolds()
+            return 2
         if not self.options.scaffold_name:
-            self.out('You must provide at least one scaffold name')
+            self.out('You must provide at least one scaffold name: -s <scaffold name>')
+            self.out('')
+            self.show_scaffolds()
             return 2
         if not self.args:
             self.out('You must provide a project name')


Test patch:
diff --git a/pyramid/tests/test_scripts/test_pcreate.py b/pyramid/tests/test_scripts/test_pcreate.py
--- a/pyramid/tests/test_scripts/test_pcreate.py
+++ b/pyramid/tests/test_scripts/test_pcreate.py
@@ -12,10 +12,10 @@ def _getTargetClass(self):
         from pyramid.scripts.pcreate import PCreateCommand
         return PCreateCommand
 
-    def _makeOne(self, *args):
+    def _makeOne(self, *args, **kw):
         effargs = ['pcreate']
         effargs.extend(args)
-        cmd = self._getTargetClass()(effargs)
+        cmd = self._getTargetClass()(effargs, **kw)
         cmd.out = self.out
         return cmd
 
@@ -34,8 +34,13 @@ def test_run_show_scaffolds_none_exist(self):
         out = self.out_.getvalue()
         self.assertTrue(out.startswith('No scaffolds available'))
 
+    def test_run_no_scaffold_no_args(self):
+        cmd = self._makeOne(quiet=True)
+        result = cmd.run()
+        self.assertEqual(result, 2)
+
     def test_run_no_scaffold_name(self):
-        cmd = self._makeOne()
+        cmd = self._makeOne('dummy')
         result = cmd.run()
         self.assertEqual(result, 2)
         out = self.out_.getvalue()