summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbecker33 <becker33@llnl.gov>2017-12-11 16:17:53 -0800
committerGitHub <noreply@github.com>2017-12-11 16:17:53 -0800
commit9d8ea009665ecde831fab8f3f9bf0778aedc3671 (patch)
tree4c0a46b4ff05ec6f368356e38bc0f4b6fa55615a
parente19aa807349cd29a4787ce3f0a256ea3cbfd502f (diff)
downloadspack-9d8ea009665ecde831fab8f3f9bf0778aedc3671.tar.gz
spack-9d8ea009665ecde831fab8f3f9bf0778aedc3671.tar.bz2
spack-9d8ea009665ecde831fab8f3f9bf0778aedc3671.tar.xz
spack-9d8ea009665ecde831fab8f3f9bf0778aedc3671.zip
add -d option for edit command (#6416)
* add -d option for edit command and improve suffix extrapolation from '.py' to use glob
-rw-r--r--lib/spack/spack/cmd/edit.py24
1 files changed, 21 insertions, 3 deletions
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
@@ -81,6 +81,10 @@ def setup_parser(subparser):
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,
help="edit the test with the supplied name")
@@ -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)