From 20d708e89c321e5da937160beb7225c0b4fce46f Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Sat, 7 Feb 2015 00:33:20 -0700 Subject: [PATCH 1/7] When running pcreate without scaffold, list scaffolds This fixes #1297 --- pyramid/scripts/pcreate.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyramid/scripts/pcreate.py b/pyramid/scripts/pcreate.py index edf2c39f75..a1479a2dd8 100644 --- a/pyramid/scripts/pcreate.py +++ b/pyramid/scripts/pcreate.py @@ -64,7 +64,9 @@ def run(self): if self.options.list: return self.show_scaffolds() 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 ') + self.out('') + self.show_scaffolds() return 2 if not self.args: self.out('You must provide a project name') From c9cb19b9e14e2d1ec9ba17691212ea706f19f61c Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Sat, 7 Feb 2015 00:35:36 -0700 Subject: [PATCH 2/7] Add changelog entry --- CHANGES.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 832a2c2166..09a4bbf88f 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -4,6 +4,11 @@ Next release Features -------- +- pcreate when run without a scaffold argument will now print information on + the missing flag, as well as a list of available scaffolds. + See https://github.com/Pylons/pyramid/pull/1566 and + https://github.com/Pylons/pyramid/issues/1297 + - Added support / testing for 'pypy3' under Tox and Travis. See https://github.com/Pylons/pyramid/pull/1469 From 665027ba49c9869abe8f0b8fe5d771c358a99e6d Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Sat, 7 Feb 2015 00:41:44 -0700 Subject: [PATCH 3/7] Update usage line to show required -s --- pyramid/scripts/pcreate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyramid/scripts/pcreate.py b/pyramid/scripts/pcreate.py index a1479a2dd8..c634119bd3 100644 --- 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 output_directory" parser = optparse.OptionParser(usage, description=description) parser.add_option('-s', '--scaffold', dest='scaffold_name', From 0786c75a63b8d861183a08c1bf74d8afe8b929e7 Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Sat, 7 Feb 2015 00:42:07 -0700 Subject: [PATCH 4/7] Show help if missing arguments This will print the full help, followed by the available scaffolds if the user just calls pcreate without any arguments/flags at all. --- pyramid/scripts/pcreate.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pyramid/scripts/pcreate.py b/pyramid/scripts/pcreate.py index c634119bd3..2d21896866 100644 --- a/pyramid/scripts/pcreate.py +++ b/pyramid/scripts/pcreate.py @@ -63,6 +63,12 @@ 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: + 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: -s ') self.out('') From 972dfae78a94ac19e97b96b36dfa91f9f7c3fed4 Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Sat, 7 Feb 2015 01:22:44 -0700 Subject: [PATCH 5/7] Fix failing test --- pyramid/tests/test_scripts/test_pcreate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyramid/tests/test_scripts/test_pcreate.py b/pyramid/tests/test_scripts/test_pcreate.py index 020721ca75..89fdea6be1 100644 --- a/pyramid/tests/test_scripts/test_pcreate.py +++ b/pyramid/tests/test_scripts/test_pcreate.py @@ -35,7 +35,7 @@ def test_run_show_scaffolds_none_exist(self): self.assertTrue(out.startswith('No scaffolds available')) 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() From 9449be0316aba5b465ffb2c02a1bb0daafccd8e6 Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Sat, 7 Feb 2015 01:50:48 -0700 Subject: [PATCH 6/7] Use hammer to fix hole --- pyramid/scripts/pcreate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyramid/scripts/pcreate.py b/pyramid/scripts/pcreate.py index 2d21896866..d2c5f8c279 100644 --- a/pyramid/scripts/pcreate.py +++ b/pyramid/scripts/pcreate.py @@ -64,7 +64,7 @@ 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: + if not self.quiet: # pragma: no cover self.parser.print_help() self.out('') self.show_scaffolds() From 58b8adf4135656efcc063eb822e4d29f6112d329 Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Sat, 7 Feb 2015 01:51:04 -0700 Subject: [PATCH 7/7] Add test for no scaffold no project name This test at least makes sure that if there is no scaffold and no project name that the command exists with error 2 --- pyramid/tests/test_scripts/test_pcreate.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pyramid/tests/test_scripts/test_pcreate.py b/pyramid/tests/test_scripts/test_pcreate.py index 89fdea6be1..63e5e63682 100644 --- 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,6 +34,11 @@ 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('dummy') result = cmd.run()