summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2016-10-30 15:57:59 -0700
committerTodd Gamblin <tgamblin@llnl.gov>2016-10-30 23:55:00 -0700
commit4be703cde0c8771cb9f128ac826db18ab91767b7 (patch)
tree92728b6d346beacb92762b451b4390a2d0060299
parent8f21332fec4c8adb5349ff90e30bb0e4f75e090e (diff)
downloadspack-4be703cde0c8771cb9f128ac826db18ab91767b7.tar.gz
spack-4be703cde0c8771cb9f128ac826db18ab91767b7.tar.bz2
spack-4be703cde0c8771cb9f128ac826db18ab91767b7.tar.xz
spack-4be703cde0c8771cb9f128ac826db18ab91767b7.zip
Allow common args to be written the same way regular args are.
-rw-r--r--lib/spack/spack/cmd/common/arguments.py68
-rw-r--r--lib/spack/spack/util/pattern.py6
2 files changed, 25 insertions, 49 deletions
diff --git a/lib/spack/spack/cmd/common/arguments.py b/lib/spack/spack/cmd/common/arguments.py
index 8cb4a4b871..ade6844813 100644
--- a/lib/spack/spack/cmd/common/arguments.py
+++ b/lib/spack/spack/cmd/common/arguments.py
@@ -27,7 +27,7 @@ import argparse
import spack.store
import spack.modules
-from spack.util.pattern import Bunch
+from spack.util.pattern import Args
__all__ = ['add_common_arguments']
_arguments = {}
@@ -60,56 +60,26 @@ class ConstraintAction(argparse.Action):
specs = [x for x in specs if x.satisfies(values, strict=True)]
namespace.specs = specs
-parms = Bunch(
- flags=('constraint',),
- kwargs={
- 'nargs': '*',
- 'help': 'Constraint to select a subset of installed packages',
- 'action': ConstraintAction
- })
-_arguments['constraint'] = parms
+_arguments['constraint'] = Args(
+ 'constraint', nargs='*', action=ConstraintAction,
+ help='Constraint to select a subset of installed packages')
-parms = Bunch(
- flags=('-m', '--module-type'),
- kwargs={
- 'help': 'Type of module files',
- 'default': 'tcl',
- 'choices': spack.modules.module_types
- })
-_arguments['module_type'] = parms
+_arguments['module_type'] = Args(
+ '-m', '--module-type', help='Type of module files',
+ default='tcl', choices=spack.modules.module_types)
-parms = Bunch(
- flags=('-y', '--yes-to-all'),
- kwargs={
- 'action': 'store_true',
- 'dest': 'yes_to_all',
- 'help': 'Assume "yes" is the answer to every confirmation request.'
- })
-_arguments['yes_to_all'] = parms
+_arguments['yes_to_all'] = Args(
+ '-y', '--yes-to-all', action='store_true', dest='yes_to_all',
+ help='Assume "yes" is the answer to every confirmation request.')
-parms = Bunch(
- flags=('-r', '--dependencies'),
- kwargs={
- 'action': 'store_true',
- 'dest': 'recurse_dependencies',
- 'help': 'Recursively traverse spec dependencies'
- })
-_arguments['recurse_dependencies'] = parms
+_arguments['recurse_dependencies'] = Args(
+ '-r', '--dependencies', action='store_true', dest='recurse_dependencies',
+ help='Recursively traverse spec dependencies')
-parms = Bunch(
- flags=('--clean',),
- kwargs={
- 'action': 'store_false',
- 'dest': 'dirty',
- 'help': 'Clean environment before installing package.'
- })
-_arguments['clean'] = parms
+_arguments['clean'] = Args(
+ '--clean', action='store_false', dest='dirty',
+ help='Clean environment before installing package.')
-parms = Bunch(
- flags=('--dirty',),
- kwargs={
- 'action': 'store_true',
- 'dest': 'dirty',
- 'help': 'Do NOT clean environment before installing.'
- })
-_arguments['dirty'] = parms
+_arguments['dirty'] = Args(
+ '--dirty', action='store_true', dest='dirty',
+ help='Do NOT clean environment before installing.')
diff --git a/lib/spack/spack/util/pattern.py b/lib/spack/spack/util/pattern.py
index 2b7f06d46e..b5731ccf08 100644
--- a/lib/spack/spack/util/pattern.py
+++ b/lib/spack/spack/util/pattern.py
@@ -140,3 +140,9 @@ class Bunch(object):
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
+
+
+class Args(Bunch):
+ """Subclass of Bunch to write argparse args more naturally."""
+ def __init__(self, *flags, **kwargs):
+ super(Args, self).__init__(flags=tuple(flags), kwargs=kwargs)