Skip to content

Instantly share code, notes, and snippets.

@danhper
Created December 19, 2015 23:33
Show Gist options
  • Save danhper/15d5a9168c56c2d377f6 to your computer and use it in GitHub Desktop.
Save danhper/15d5a9168c56c2d377f6 to your computer and use it in GitHub Desktop.
function __fundle_next_arg -a index
set -l args $argv[2..-1]
set -l arg_index (math $index + 1)
if test (count $args) -lt $arg_index
echo "missing argument for $args[$index]"
return 1
end
set -l arg $args[$arg_index]
switch $arg
case '--*'
echo "expected argument for $args[$index], got $arg"; and return 1
case '*'
echo $arg; and return 0
end
end
# in __fundle_plugin
set -l skip_next true
for i in (__fundle_seq (count $argv))
test $skip_next = true; and set skip_next false; and continue
set -l arg $argv[$i]
switch $arg
case '--url'
set plugin_url (__fundle_next_arg $i $argv)
test $status -eq 1; and echo $plugin_url; and return 1
set skip_next true
case '--path'
set plugin_path (__fundle_next_arg $i $argv)
test $status -eq 1; and echo $plugin_path; and return 1
set skip_next true
case '--*'
echo "unknown flag $arg"; and return 1
case '*'
test $i -ne 2; and echo "invalid argument $arg"; and return 1
set plugin_url $arg
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment