2015-12-20 17:57:51 -02:00
|
|
|
function omf -d "Oh My Fish"
|
2017-02-12 23:02:42 -06:00
|
|
|
# Parse any options before the command name.
|
|
|
|
while set -q argv[1]
|
|
|
|
switch $argv[1]
|
|
|
|
case '-h' '--help' '-\?' '/\?'
|
|
|
|
set command help
|
2015-12-20 17:57:51 -02:00
|
|
|
|
2017-02-12 23:02:42 -06:00
|
|
|
case '-v' '--version'
|
|
|
|
set command version
|
2016-02-23 22:59:10 -03:00
|
|
|
|
2017-02-12 23:02:42 -06:00
|
|
|
case '-?*'
|
|
|
|
echo (omf::err)"Unknown option: $argv[1]"(omf::off) >&2
|
|
|
|
return $OMF_UNKNOWN_OPT
|
2015-12-20 17:57:51 -02:00
|
|
|
|
2017-02-12 23:02:42 -06:00
|
|
|
case '*'
|
|
|
|
break
|
|
|
|
end
|
2015-12-20 17:57:51 -02:00
|
|
|
|
2017-02-12 23:02:42 -06:00
|
|
|
set -e argv[1]
|
|
|
|
end
|
2015-12-20 17:57:51 -02:00
|
|
|
|
2017-02-12 23:02:42 -06:00
|
|
|
# Also extract a help flag from the last argument.
|
|
|
|
switch "$argv[-1]"
|
|
|
|
case '-h' '--help' '-\?' '/\?'
|
|
|
|
set command help
|
|
|
|
set -e argv[-1]
|
|
|
|
end
|
2017-02-04 21:49:39 -06:00
|
|
|
|
2017-02-12 23:02:42 -06:00
|
|
|
# Extract the command name from the remaining arguments.
|
|
|
|
if not set -q command
|
|
|
|
if set -q argv[1]
|
|
|
|
set command $argv[1]
|
|
|
|
set -e argv[1]
|
|
|
|
else
|
|
|
|
set command help
|
|
|
|
end
|
|
|
|
end
|
2016-10-20 18:10:13 -05:00
|
|
|
|
2017-02-12 23:02:42 -06:00
|
|
|
# Lookup the function for the requested command.
|
|
|
|
if not set command_name (omf.command $command)
|
|
|
|
echo (omf::err)"Unknown command: $command"(omf::off) >&2
|
|
|
|
return $OMF_UNKNOWN_OPT
|
|
|
|
end
|
2016-05-11 19:29:50 +01:00
|
|
|
|
2017-02-12 23:02:42 -06:00
|
|
|
# Execute the command.
|
|
|
|
echo "function __omf_last_command --no-scope-shadowing
|
|
|
|
omf.cli.$command_name \$argv
|
|
|
|
end" | source
|
2016-10-20 18:10:13 -05:00
|
|
|
|
2017-02-12 23:02:42 -06:00
|
|
|
__omf_last_command $argv
|
2015-12-20 17:57:51 -02:00
|
|
|
end
|