Better spack -h: added cmd descriptions.
- each cmd has a desscription attribute that is used for the help strign in argparse.
This commit is contained in:
@@ -3,11 +3,14 @@
|
||||
|
||||
import spack
|
||||
import spack.tty as tty
|
||||
import spack.attr as attr
|
||||
|
||||
# Patterns to ignore in the commands directory when looking for commands.
|
||||
ignore_files = r'^\.|^__init__.py$|^#'
|
||||
|
||||
setup_parser = "setup_parser"
|
||||
SETUP_PARSER = "setup_parser"
|
||||
DESCRIPTION = "description"
|
||||
|
||||
command_path = os.path.join(spack.lib_path, "spack", "cmd")
|
||||
|
||||
commands = []
|
||||
@@ -25,8 +28,12 @@ def null_op(*args):
|
||||
def get_module(name):
|
||||
"""Imports the module for a particular command name and returns it."""
|
||||
module_name = "%s.%s" % (__name__, name)
|
||||
module = __import__(module_name, fromlist=[name, setup_parser], level=0)
|
||||
module.setup_parser = getattr(module, setup_parser, null_op)
|
||||
module = __import__(
|
||||
module_name, fromlist=[name, SETUP_PARSER, DESCRIPTION],
|
||||
level=0)
|
||||
|
||||
attr.setdefault(module, SETUP_PARSER, null_op)
|
||||
attr.setdefault(module, DESCRIPTION, "")
|
||||
|
||||
if not hasattr(module, name):
|
||||
tty.die("Command module %s (%s) must define function '%s'."
|
||||
|
@@ -2,6 +2,8 @@
|
||||
import spack.tty as tty
|
||||
import spack.stage as stage
|
||||
|
||||
description = "Remove staged files for packages"
|
||||
|
||||
def setup_parser(subparser):
|
||||
subparser.add_argument('names', nargs='+', help="name(s) of package(s) to clean")
|
||||
subparser.add_argument('-c', "--clean", action="store_true", dest='clean',
|
||||
|
@@ -9,6 +9,8 @@
|
||||
from spack.stage import Stage
|
||||
from contextlib import closing
|
||||
|
||||
description = "Create a new package file from an archive URL"
|
||||
|
||||
package_template = string.Template("""\
|
||||
from spack import *
|
||||
|
||||
|
@@ -3,6 +3,7 @@
|
||||
import spack.packages as packages
|
||||
import spack.tty as tty
|
||||
|
||||
description = "Open package files in $EDITOR"
|
||||
|
||||
def setup_parser(subparser):
|
||||
subparser.add_argument(
|
||||
|
@@ -1,5 +1,7 @@
|
||||
import spack.packages as packages
|
||||
|
||||
description = "Fetch archives for packages"
|
||||
|
||||
def setup_parser(subparser):
|
||||
subparser.add_argument('name', help="name of package to fetch")
|
||||
subparser.add_argument('-f', '--file', dest='file', default=None,
|
||||
|
@@ -1,6 +1,7 @@
|
||||
import spack
|
||||
import spack.packages as packages
|
||||
|
||||
description = "Write out inter-package dependencies in dot graph format"
|
||||
|
||||
def graph(parser, args):
|
||||
packages.graph_dependencies()
|
||||
|
@@ -1,5 +1,7 @@
|
||||
import sys
|
||||
|
||||
description = "Get help on spack and its commands"
|
||||
|
||||
def setup_parser(subparser):
|
||||
subparser.add_argument('help_command', nargs='?', default=None,
|
||||
help='command to get help on')
|
||||
|
@@ -1,6 +1,8 @@
|
||||
import spack
|
||||
import spack.packages as packages
|
||||
|
||||
description = "Build and install packages"
|
||||
|
||||
def setup_parser(subparser):
|
||||
subparser.add_argument('names', nargs='+', help="name(s) of package(s) to install")
|
||||
subparser.add_argument('-i', '--ignore-dependencies',
|
||||
|
@@ -2,6 +2,7 @@
|
||||
import spack.packages as packages
|
||||
from spack.colify import colify
|
||||
|
||||
description ="List spack packages"
|
||||
|
||||
def setup_parser(subparser):
|
||||
subparser.add_argument('-i', '--installed', action='store_true', dest='installed',
|
||||
|
@@ -1,4 +1,6 @@
|
||||
import spack.stage as stage
|
||||
|
||||
description = "Remove all temporary build files and downloaded archives"
|
||||
|
||||
def purge(parser, args):
|
||||
stage.purge()
|
||||
|
@@ -1,5 +1,7 @@
|
||||
import spack.packages as packages
|
||||
|
||||
description="Expand downloaded archive in preparation for install"
|
||||
|
||||
def setup_parser(subparser):
|
||||
subparser.add_argument('name', help="name of package to stage")
|
||||
|
||||
|
@@ -1,5 +1,7 @@
|
||||
import spack.packages as packages
|
||||
|
||||
description="Remove an installed package"
|
||||
|
||||
def setup_parser(subparser):
|
||||
subparser.add_argument('names', nargs='+', help="name(s) of package(s) to uninstall")
|
||||
subparser.add_argument('-f', '--force', action='store_true', dest='force',
|
||||
|
Reference in New Issue
Block a user