Skip to content
Snippets Groups Projects
Commit 4be703cd authored by Todd Gamblin's avatar Todd Gamblin
Browse files

Allow common args to be written the same way regular args are.

parent 8f21332f
No related branches found
No related tags found
No related merge requests found
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
import spack.store import spack.store
import spack.modules import spack.modules
from spack.util.pattern import Bunch from spack.util.pattern import Args
__all__ = ['add_common_arguments'] __all__ = ['add_common_arguments']
_arguments = {} _arguments = {}
...@@ -60,56 +60,26 @@ def __call__(self, parser, namespace, values, option_string=None): ...@@ -60,56 +60,26 @@ def __call__(self, parser, namespace, values, option_string=None):
specs = [x for x in specs if x.satisfies(values, strict=True)] specs = [x for x in specs if x.satisfies(values, strict=True)]
namespace.specs = specs namespace.specs = specs
parms = Bunch( _arguments['constraint'] = Args(
flags=('constraint',), 'constraint', nargs='*', action=ConstraintAction,
kwargs={ help='Constraint to select a subset of installed packages')
'nargs': '*',
'help': 'Constraint to select a subset of installed packages',
'action': ConstraintAction
})
_arguments['constraint'] = parms
parms = Bunch( _arguments['module_type'] = Args(
flags=('-m', '--module-type'), '-m', '--module-type', help='Type of module files',
kwargs={ default='tcl', choices=spack.modules.module_types)
'help': 'Type of module files',
'default': 'tcl',
'choices': spack.modules.module_types
})
_arguments['module_type'] = parms
parms = Bunch( _arguments['yes_to_all'] = Args(
flags=('-y', '--yes-to-all'), '-y', '--yes-to-all', action='store_true', dest='yes_to_all',
kwargs={ help='Assume "yes" is the answer to every confirmation request.')
'action': 'store_true',
'dest': 'yes_to_all',
'help': 'Assume "yes" is the answer to every confirmation request.'
})
_arguments['yes_to_all'] = parms
parms = Bunch( _arguments['recurse_dependencies'] = Args(
flags=('-r', '--dependencies'), '-r', '--dependencies', action='store_true', dest='recurse_dependencies',
kwargs={ help='Recursively traverse spec dependencies')
'action': 'store_true',
'dest': 'recurse_dependencies',
'help': 'Recursively traverse spec dependencies'
})
_arguments['recurse_dependencies'] = parms
parms = Bunch( _arguments['clean'] = Args(
flags=('--clean',), '--clean', action='store_false', dest='dirty',
kwargs={ help='Clean environment before installing package.')
'action': 'store_false',
'dest': 'dirty',
'help': 'Clean environment before installing package.'
})
_arguments['clean'] = parms
parms = Bunch( _arguments['dirty'] = Args(
flags=('--dirty',), '--dirty', action='store_true', dest='dirty',
kwargs={ help='Do NOT clean environment before installing.')
'action': 'store_true',
'dest': 'dirty',
'help': 'Do NOT clean environment before installing.'
})
_arguments['dirty'] = parms
...@@ -140,3 +140,9 @@ class Bunch(object): ...@@ -140,3 +140,9 @@ class Bunch(object):
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.__dict__.update(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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment