Change the action from parameter to subcommand to fit Spack convention.
This commit is contained in:
parent
a2b9a000dc
commit
8c140f4725
@ -41,17 +41,30 @@
|
|||||||
def setup_parser(subparser):
|
def setup_parser(subparser):
|
||||||
setup_parser.parser = subparser
|
setup_parser.parser = subparser
|
||||||
|
|
||||||
subparser.add_argument('-e','--exclude', action='append', default=[],
|
sp = subparser.add_subparsers(metavar='ACTION', dest='action')
|
||||||
help="exclude any packages which the given re pattern")
|
|
||||||
subparser.add_argument('-a','--action', default='link',
|
# The action parameterizes the command but in keeping with Spack
|
||||||
choices=['link','remove','status'], # names match action_*() functions below
|
# patterns we make it a subcommand.
|
||||||
help="what action to perform on the view")
|
sps = [
|
||||||
subparser.add_argument('--no-dependencies', action='store_true', default=False,
|
sp.add_parser('link', aliases=['add'],
|
||||||
help="just operate on named packages and do not follow dependencies")
|
help='Add packages to the view, create view if needed.'),
|
||||||
subparser.add_argument('-p','--prefix', required=True,
|
sp.add_parser('remove', aliases=['rm'],
|
||||||
help="Path to a top-level directory to receive the view.")
|
help='Remove packages from the view, and view if empty.'),
|
||||||
subparser.add_argument('specs', nargs=argparse.REMAINDER,
|
sp.add_parser('status', aliases=['check'],
|
||||||
help="specs of packages to expose in the view.")
|
help='Check status of packages in the view.')
|
||||||
|
]
|
||||||
|
|
||||||
|
# All these options and arguments are common to every action.
|
||||||
|
for p in sps:
|
||||||
|
p.add_argument('-e','--exclude', action='append', default=[],
|
||||||
|
help="exclude any packages which the given re pattern")
|
||||||
|
p.add_argument('--no-dependencies', action='store_true', default=False,
|
||||||
|
help="just operate on named packages and do not follow dependencies")
|
||||||
|
p.add_argument('prefix', nargs=1,
|
||||||
|
help="Path to a top-level directory to receive the view.")
|
||||||
|
p.add_argument('specs', nargs=argparse.REMAINDER,
|
||||||
|
help="specs of packages to expose in the view.")
|
||||||
|
|
||||||
|
|
||||||
def assuredir(path):
|
def assuredir(path):
|
||||||
'Assure path exists as a directory'
|
'Assure path exists as a directory'
|
||||||
@ -151,7 +164,9 @@ def purge_empty_directories(path):
|
|||||||
tty.warn("Not removing directory with contents: %s" % sdp)
|
tty.warn("Not removing directory with contents: %s" % sdp)
|
||||||
|
|
||||||
|
|
||||||
def view(parser, args):
|
|
||||||
|
|
||||||
|
def view_action(action, parser, args):
|
||||||
'The view command.'
|
'The view command.'
|
||||||
to_exclude = [re.compile(e) for e in args.exclude]
|
to_exclude = [re.compile(e) for e in args.exclude]
|
||||||
def exclude(spec):
|
def exclude(spec):
|
||||||
@ -162,7 +177,7 @@ def exclude(spec):
|
|||||||
|
|
||||||
specs = spack.cmd.parse_specs(args.specs, normalize=True, concretize=True)
|
specs = spack.cmd.parse_specs(args.specs, normalize=True, concretize=True)
|
||||||
if not specs:
|
if not specs:
|
||||||
setup_parser.parser.print_help()
|
parser.print_help()
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
prefix = args.prefix
|
prefix = args.prefix
|
||||||
@ -175,9 +190,6 @@ def exclude(spec):
|
|||||||
continue
|
continue
|
||||||
flat.update(spec.normalized().traverse())
|
flat.update(spec.normalized().traverse())
|
||||||
|
|
||||||
action = args.action.lower()
|
|
||||||
method = eval('action_' + action)
|
|
||||||
|
|
||||||
for spec in flat:
|
for spec in flat:
|
||||||
if exclude(spec):
|
if exclude(spec):
|
||||||
tty.info('Skipping excluded package: "%s"' % spec.name)
|
tty.info('Skipping excluded package: "%s"' % spec.name)
|
||||||
@ -186,7 +198,19 @@ def exclude(spec):
|
|||||||
tty.warn('Skipping unknown package: %s in %s' % (spec.name, spec.prefix))
|
tty.warn('Skipping unknown package: %s in %s' % (spec.name, spec.prefix))
|
||||||
continue
|
continue
|
||||||
tty.info("%s %s" % (action, spec.name))
|
tty.info("%s %s" % (action, spec.name))
|
||||||
method(spec, prefix)
|
action(spec, prefix)
|
||||||
|
|
||||||
if action in ['remove']:
|
if action in ['remove']:
|
||||||
purge_empty_directories(prefix)
|
purge_empty_directories(prefix)
|
||||||
|
|
||||||
|
|
||||||
|
def view(parser, args):
|
||||||
|
action = {
|
||||||
|
'add': action_link,
|
||||||
|
'link': action_link,
|
||||||
|
'remove': action_remove,
|
||||||
|
'rm': action_remove,
|
||||||
|
'status': action_status,
|
||||||
|
'check': action_status
|
||||||
|
}[args.action]
|
||||||
|
view_action(action, parser, args)
|
||||||
|
Loading…
Reference in New Issue
Block a user