From 9d8ea009665ecde831fab8f3f9bf0778aedc3671 Mon Sep 17 00:00:00 2001 From: becker33 Date: Mon, 11 Dec 2017 16:17:53 -0800 Subject: add -d option for edit command (#6416) * add -d option for edit command and improve suffix extrapolation from '.py' to use glob --- lib/spack/spack/cmd/edit.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/spack/spack/cmd/edit.py b/lib/spack/spack/cmd/edit.py index 48d423a97e..3e88a13389 100644 --- a/lib/spack/spack/cmd/edit.py +++ b/lib/spack/spack/cmd/edit.py @@ -23,9 +23,9 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ############################################################################## import os +import glob import llnl.util.tty as tty -from llnl.util.filesystem import join_path import spack import spack.cmd @@ -80,6 +80,10 @@ def setup_parser(subparser): '-c', '--command', dest='path', action='store_const', const=spack.cmd.command_path, help="edit the command with the supplied name") + excl_args.add_argument( + '-d', '--docs', dest='path', action='store_const', + const=os.path.join(spack.lib_path, 'docs'), + help="edit the docs with the supplied name") excl_args.add_argument( '-t', '--test', dest='path', action='store_const', const=spack.test_path, @@ -112,9 +116,23 @@ def edit(parser, args): if args.path: path = args.path if name: - path = join_path(path, name + ".py") + path = os.path.join(path, name) if not os.path.exists(path): - tty.die("No command for '{0}' was found.".format(name)) + files = glob.glob(path + '*') + blacklist = ['.pyc', '~'] # blacklist binaries and backups + files = filter(lambda x: all(s not in x for s in blacklist), + files) + if len(files) > 1: + m = 'Multiple files exist with the name {0}.'.format(name) + m += ' Please specify a suffix. Files are:\n\n' + for f in files: + m += ' ' + os.path.basename(f) + '\n' + tty.die(m) + if not files: + tty.die("No file for '{0}' was found in {1}".format(name, + path)) + path = files[0] # already confirmed only one entry in files + spack.editor(path) elif name: edit_package(name, args.repo, args.namespace) -- cgit v1.2.3-70-g09d2