Add spack edit -c option to edit commands.

This commit is contained in:
Todd Gamblin 2014-10-07 23:52:32 -07:00
parent ff546358f3
commit 319b37af0e

View File

@ -27,9 +27,10 @@
from contextlib import closing
import llnl.util.tty as tty
from llnl.util.filesystem import mkdirp
from llnl.util.filesystem import mkdirp, join_path
import spack
import spack.cmd
from spack.util.naming import mod_to_class
description = "Open package files in $EDITOR"
@ -57,6 +58,9 @@ def setup_parser(subparser):
subparser.add_argument(
'-f', '--force', dest='force', action='store_true',
help="Open a new file in $EDITOR even if package doesn't exist.")
subparser.add_argument(
'-c', '--command', dest='edit_command', action='store_true',
help="Edit the command with the supplied name instead of a package.")
subparser.add_argument(
'name', nargs='?', default=None, help="name of package to edit")
@ -64,7 +68,16 @@ def setup_parser(subparser):
def edit(parser, args):
name = args.name
# By default open the directory where packages live.
if args.edit_command:
if not name:
path = spack.cmd.command_path
else:
path = join_path(spack.cmd.command_path, name + ".py")
if not os.path.exists(path):
tty.die("No command named '%s'." % name)
else:
# By default open the directory where packages or commands live.
if not name:
path = spack.packages_path
else: