summaryrefslogtreecommitdiff
path: root/share
diff options
context:
space:
mode:
authorJohannes Blaschke <johannes.blaschke@gmail.com>2020-09-10 08:01:44 -0700
committerGitHub <noreply@github.com>2020-09-10 10:01:44 -0500
commit757dad370fa950985c506cad64478db891648aab (patch)
treef9e9aaee8d0fcdb7d5f76b273ba7299b1850ed7d /share
parent2bc9821c431088d40a263dd2277569281dab8ca5 (diff)
downloadspack-757dad370fa950985c506cad64478db891648aab.tar.gz
spack-757dad370fa950985c506cad64478db891648aab.tar.bz2
spack-757dad370fa950985c506cad64478db891648aab.tar.xz
spack-757dad370fa950985c506cad64478db891648aab.zip
Bugfix for fish support: overly zealous arg matching (#18528)
* bugfix for issue 18369 * fix typo Co-authored-by: Adam J. Stewart <ajstewart426@gmail.com> Co-authored-by: Adam J. Stewart <ajstewart426@gmail.com>
Diffstat (limited to 'share')
-rwxr-xr-xshare/spack/setup-env.fish77
1 files changed, 59 insertions, 18 deletions
diff --git a/share/spack/setup-env.fish b/share/spack/setup-env.fish
index dd2a17f74f..b74eae34d6 100755
--- a/share/spack/setup-env.fish
+++ b/share/spack/setup-env.fish
@@ -246,9 +246,46 @@ end
+function match_flag -d "checks all combinations of flags ocurring inside of a string"
+
+ # Remove leading and trailing spaces -- but we need to insert a "guard" (x)
+ # so that eg. `string trim -h` doesn't trigger the help string for `string trim`
+ set -l _a (string sub -s 2 (string trim "x$argv[1]"))
+ set -l _b (string sub -s 2 (string trim "x$argv[2]"))
+
+ if test -z "$_a" || test -z "$_b"
+ return 0
+ end
+
+ # surrounded by spaced
+ if echo "$_a" | string match -r -q " +$_b +"
+ return 0
+ end
+
+ # beginning of string + trailing space
+ if echo "$_a" | string match -r -q "^$_b +"
+ return 0
+ end
+
+ # end of string + leadingg space
+ if echo "$_a" | string match -r -q " +$_b\$"
+ return 0
+ end
+
+ # entire string
+ if echo "$_a" | string match -r -q "^$_b\$"
+ return 0
+ end
+
+ return 1
+
+end
+
+
+
function check_env_activate_flags -d "check spack env subcommand flags for -h, --sh, --csh, or --fish"
#
- # Check if inputs contain -h, --sh, --csh, or --fish
+ # Check if inputs contain -h/--help, --sh, --csh, or --fish
#
# combine argument array into single string (space seperated), to be passed
@@ -257,23 +294,29 @@ function check_env_activate_flags -d "check spack env subcommand flags for -h, -
# skip if called with blank input. Notes: [1] (cf. EOF)
if test -n "$_a"
- # looks for a single `-h` (possibly surrounded by spaces)
- if echo $_a | string match -r -q " *-h *"
+
+ # looks for a single `-h`
+ if match_flag $_a "-h"
+ return 0
+ end
+
+ # looks for a single `--help`
+ if match_flag $_a "--help"
return 0
end
- # looks for a single `--sh` (possibly surrounded by spaces)
- if echo $_a | string match -r -q " *--sh *"
+ # looks for a single `--sh`
+ if match_flag $_a "--sh"
return 0
end
- # looks for a single `--csh` (possibly surrounded by spaces)
- if echo $_a | string match -r -q " *--csh *"
+ # looks for a single `--csh`
+ if match_flag $_a "--csh"
return 0
end
- # looks for a single `--fish` (possibly surrounded by spaces)
- if echo $_a | string match -r -q " *--fish *"
+ # looks for a single `--fish`
+ if match_flag $_a "--fish"
return 0
end
@@ -285,7 +328,7 @@ end
function check_env_deactivate_flags -d "check spack env subcommand flags for --sh, --csh, or --fish"
#
- # Check if inputs contain -h, --sh, --csh, or --fish
+ # Check if inputs contain --sh, --csh, or --fish
#
# combine argument array into single string (space seperated), to be passed
@@ -295,20 +338,18 @@ function check_env_deactivate_flags -d "check spack env subcommand flags for --s
# skip if called with blank input. Notes: [1] (cf. EOF)
if test -n "$_a"
- # TODO: should this crash (we're clearly using fish, not bash, here)?
- # looks for a single `--sh` (possibly surrounded by spaces)
- if echo $_a | string match -r -q " *--sh *"
+ # looks for a single `--sh`
+ if match_flag $_a "--sh"
return 0
end
- # TODO: should this crash (we're clearly using fish, not csh, here)?
- # looks for a single `--csh` (possibly surrounded by spaces)
- if echo $_a | string match -r -q " *--csh *"
+ # looks for a single `--csh`
+ if match_flag $_a "--csh"
return 0
end
- # looks for a single `--fish` (possibly surrounded by spaces)
- if echo $_a | string match -r -q " *--fish *"
+ # looks for a single `--fish`
+ if match_flag $_a "--fish"
return 0
end