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:
parent
707db8dafe
commit
27b9204785
13 changed files with 36 additions and 7 deletions
11
bin/spack
11
bin/spack
|
@ -19,9 +19,12 @@ import spack
|
||||||
# Command parsing
|
# Command parsing
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description='Spack: the Supercomputing PACKage Manager.')
|
description='Spack: the Supercomputing PACKage Manager.')
|
||||||
parser.add_argument('-V', '--version', action='version', version="%s" % spack.spack_version)
|
parser.add_argument('-V', '--version', action='version',
|
||||||
parser.add_argument('-v', '--verbose', action='store_true', dest='verbose')
|
version="%s" % spack.spack_version)
|
||||||
parser.add_argument('-d', '--debug', action='store_true', dest='debug')
|
parser.add_argument('-v', '--verbose', action='store_true', dest='verbose',
|
||||||
|
help="print additional output during builds")
|
||||||
|
parser.add_argument('-d', '--debug', action='store_true', dest='debug',
|
||||||
|
help="write out debug logs during compile")
|
||||||
|
|
||||||
# each command module implements a parser() function, to which we pass its
|
# each command module implements a parser() function, to which we pass its
|
||||||
# subparser for setup.
|
# subparser for setup.
|
||||||
|
@ -29,8 +32,8 @@ subparsers = parser.add_subparsers(title="subcommands", dest="command")
|
||||||
|
|
||||||
import spack.cmd
|
import spack.cmd
|
||||||
for cmd in spack.cmd.commands:
|
for cmd in spack.cmd.commands:
|
||||||
subparser = subparsers.add_parser(cmd)
|
|
||||||
module = spack.cmd.get_module(cmd)
|
module = spack.cmd.get_module(cmd)
|
||||||
|
subparser = subparsers.add_parser(cmd, help=module.description)
|
||||||
module.setup_parser(subparser)
|
module.setup_parser(subparser)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
|
|
@ -3,11 +3,14 @@
|
||||||
|
|
||||||
import spack
|
import spack
|
||||||
import spack.tty as tty
|
import spack.tty as tty
|
||||||
|
import spack.attr as attr
|
||||||
|
|
||||||
# Patterns to ignore in the commands directory when looking for commands.
|
# Patterns to ignore in the commands directory when looking for commands.
|
||||||
ignore_files = r'^\.|^__init__.py$|^#'
|
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")
|
command_path = os.path.join(spack.lib_path, "spack", "cmd")
|
||||||
|
|
||||||
commands = []
|
commands = []
|
||||||
|
@ -25,8 +28,12 @@ def null_op(*args):
|
||||||
def get_module(name):
|
def get_module(name):
|
||||||
"""Imports the module for a particular command name and returns it."""
|
"""Imports the module for a particular command name and returns it."""
|
||||||
module_name = "%s.%s" % (__name__, name)
|
module_name = "%s.%s" % (__name__, name)
|
||||||
module = __import__(module_name, fromlist=[name, setup_parser], level=0)
|
module = __import__(
|
||||||
module.setup_parser = getattr(module, setup_parser, null_op)
|
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):
|
if not hasattr(module, name):
|
||||||
tty.die("Command module %s (%s) must define function '%s'."
|
tty.die("Command module %s (%s) must define function '%s'."
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
import spack.tty as tty
|
import spack.tty as tty
|
||||||
import spack.stage as stage
|
import spack.stage as stage
|
||||||
|
|
||||||
|
description = "Remove staged files for packages"
|
||||||
|
|
||||||
def setup_parser(subparser):
|
def setup_parser(subparser):
|
||||||
subparser.add_argument('names', nargs='+', help="name(s) of package(s) to clean")
|
subparser.add_argument('names', nargs='+', help="name(s) of package(s) to clean")
|
||||||
subparser.add_argument('-c', "--clean", action="store_true", dest='clean',
|
subparser.add_argument('-c', "--clean", action="store_true", dest='clean',
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
from spack.stage import Stage
|
from spack.stage import Stage
|
||||||
from contextlib import closing
|
from contextlib import closing
|
||||||
|
|
||||||
|
description = "Create a new package file from an archive URL"
|
||||||
|
|
||||||
package_template = string.Template("""\
|
package_template = string.Template("""\
|
||||||
from spack import *
|
from spack import *
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
import spack.packages as packages
|
import spack.packages as packages
|
||||||
import spack.tty as tty
|
import spack.tty as tty
|
||||||
|
|
||||||
|
description = "Open package files in $EDITOR"
|
||||||
|
|
||||||
def setup_parser(subparser):
|
def setup_parser(subparser):
|
||||||
subparser.add_argument(
|
subparser.add_argument(
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import spack.packages as packages
|
import spack.packages as packages
|
||||||
|
|
||||||
|
description = "Fetch archives for packages"
|
||||||
|
|
||||||
def setup_parser(subparser):
|
def setup_parser(subparser):
|
||||||
subparser.add_argument('name', help="name of package to fetch")
|
subparser.add_argument('name', help="name of package to fetch")
|
||||||
subparser.add_argument('-f', '--file', dest='file', default=None,
|
subparser.add_argument('-f', '--file', dest='file', default=None,
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import spack
|
import spack
|
||||||
import spack.packages as packages
|
import spack.packages as packages
|
||||||
|
|
||||||
|
description = "Write out inter-package dependencies in dot graph format"
|
||||||
|
|
||||||
def graph(parser, args):
|
def graph(parser, args):
|
||||||
packages.graph_dependencies()
|
packages.graph_dependencies()
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
description = "Get help on spack and its commands"
|
||||||
|
|
||||||
def setup_parser(subparser):
|
def setup_parser(subparser):
|
||||||
subparser.add_argument('help_command', nargs='?', default=None,
|
subparser.add_argument('help_command', nargs='?', default=None,
|
||||||
help='command to get help on')
|
help='command to get help on')
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import spack
|
import spack
|
||||||
import spack.packages as packages
|
import spack.packages as packages
|
||||||
|
|
||||||
|
description = "Build and install packages"
|
||||||
|
|
||||||
def setup_parser(subparser):
|
def setup_parser(subparser):
|
||||||
subparser.add_argument('names', nargs='+', help="name(s) of package(s) to install")
|
subparser.add_argument('names', nargs='+', help="name(s) of package(s) to install")
|
||||||
subparser.add_argument('-i', '--ignore-dependencies',
|
subparser.add_argument('-i', '--ignore-dependencies',
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
import spack.packages as packages
|
import spack.packages as packages
|
||||||
from spack.colify import colify
|
from spack.colify import colify
|
||||||
|
|
||||||
|
description ="List spack packages"
|
||||||
|
|
||||||
def setup_parser(subparser):
|
def setup_parser(subparser):
|
||||||
subparser.add_argument('-i', '--installed', action='store_true', dest='installed',
|
subparser.add_argument('-i', '--installed', action='store_true', dest='installed',
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
import spack.stage as stage
|
import spack.stage as stage
|
||||||
|
|
||||||
|
description = "Remove all temporary build files and downloaded archives"
|
||||||
|
|
||||||
def purge(parser, args):
|
def purge(parser, args):
|
||||||
stage.purge()
|
stage.purge()
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import spack.packages as packages
|
import spack.packages as packages
|
||||||
|
|
||||||
|
description="Expand downloaded archive in preparation for install"
|
||||||
|
|
||||||
def setup_parser(subparser):
|
def setup_parser(subparser):
|
||||||
subparser.add_argument('name', help="name of package to stage")
|
subparser.add_argument('name', help="name of package to stage")
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import spack.packages as packages
|
import spack.packages as packages
|
||||||
|
|
||||||
|
description="Remove an installed package"
|
||||||
|
|
||||||
def setup_parser(subparser):
|
def setup_parser(subparser):
|
||||||
subparser.add_argument('names', nargs='+', help="name(s) of package(s) to uninstall")
|
subparser.add_argument('names', nargs='+', help="name(s) of package(s) to uninstall")
|
||||||
subparser.add_argument('-f', '--force', action='store_true', dest='force',
|
subparser.add_argument('-f', '--force', action='store_true', dest='force',
|
||||||
|
|
Loading…
Reference in a new issue