Add default commands and command descriptions

This commit is contained in:
mitchell 2020-09-29 15:32:30 -04:00
parent cbb5b0202b
commit d7e8a2781a
1 changed files with 28 additions and 6 deletions

34
run
View File

@ -4,6 +4,7 @@
### Config ### ### Config ###
# Top-level configurations, like function prefixes and argument delimeters # Top-level configurations, like function prefixes and argument delimeters
#
set -g run_func_prefix 'run' set -g run_func_prefix 'run'
set -g run_arg_delimeter ':' set -g run_arg_delimeter ':'
@ -12,22 +13,22 @@ set -g run_arg_delimeter ':'
# Add, edit, and remove commands freely below. # Add, edit, and remove commands freely below.
# To add a command simply create a function with this naming scheme: {run_func_prefix}_{name}. # To add a command simply create a function with this naming scheme: {run_func_prefix}_{name}.
# #
function run_hello function run_hello -d 'Say hello to the world'
echo 'hello, world!' echo 'hello, world!'
end end
function run_hey -a name function run_hey -a name -d 'Say hey to someone specific'
echo "hey, $name!" echo "hey, $name!"
end end
function run_lang -a command function run_lang -a command -d 'Groups lang subcommands'
function lang_en function lang_en -d 'Say hello in english'
run_hello run_hello
end end
function lang_fr -a name function lang_fr -a name -d 'Say hello the world or someone specific, in french'
if test -n "$name" if test -n "$name"
echo "bounjour, $name!" echo "bonjour, $name!"
else else
echo 'bonjour, le monde!' echo 'bonjour, le monde!'
end end
@ -36,6 +37,26 @@ function run_lang -a command
execute_command 'lang' $command execute_command 'lang' $command
end end
### Default Commands ###
# Below is a set of default commands, like help and commands. Give them a try by doing:
# ./run help
# ./run help:hello
# ./run commands
#
function "$run_func_prefix"_commands -d 'List all available commands'
functions --names | grep $run_func_prefix'_' | string replace $run_func_prefix'_' ''
end
function "$run_func_prefix"_help -a command -d 'Print command definition'
if test -n "$command"
functions $run_func_prefix'_'$command
else
echo 'Here are the available commands:'
$run_func_prefix'_commands'
echo \n"To see a command's definition and description do `./run help$run_arg_delimeter{command}`"
end
end
### Command Execution ### ### Command Execution ###
# Do not edit, unless you want to alter how the script executes commands. # Do not edit, unless you want to alter how the script executes commands.
# #
@ -65,6 +86,7 @@ function execute_command -a prefix command
$func $args[2] $func $args[2]
else else
echo "$prefix command '$command' does not exist" echo "$prefix command '$command' does not exist"
exit 1
end end
end end