From 40fbe45f05ff4cef1e4bf9d6d03680a7d5558afa Mon Sep 17 00:00:00 2001 From: James Dinsdale Date: Fri, 2 Sep 2016 22:44:17 +0100 Subject: [PATCH] Add usage information and completion file --- revolver | 36 +++++++++++++++++++++++++++++++++++- revolver.zsh-completion | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 revolver.zsh-completion diff --git a/revolver b/revolver index 90174b9..503a2ff 100755 --- a/revolver +++ b/revolver @@ -1,5 +1,22 @@ #!/usr/bin/env zsh +### +# Output usage information and exit +### +function _revolver_usage() { + echo "\033[0;33mUsage:\033[0;m" + echo " revolver [options] " + echo + echo "\033[0;33mOptions:\033[0;m" + echo " -h, --help Output help text and exit" + echo " -v, --version Output version information and exit" + echo + echo "\033[0;33mCommands:\033[0;m" + echo " start Start the spinner" + echo " update Update the message" + echo " stop Stop the spinner" +} + ### # The main revolver process, which contains the loop ### @@ -155,7 +172,24 @@ function _revolver_start() { ### function _revolver() { # Get the context from the first parameter - local ctx="$1" + local help version ctx="$1" + + # Parse CLI options + zparseopts -D \ + h=help -help=help \ + v=version -version=version + + # Output usage information and exit + if [[ $help ]]; then + _revolver_usage + exit 0 + fi + + # Output version information and exit + if [[ $version ]]; then + echo '0.1.1' + exit 0 + fi case $ctx in start|update|stop) diff --git a/revolver.zsh-completion b/revolver.zsh-completion new file mode 100644 index 0000000..874117e --- /dev/null +++ b/revolver.zsh-completion @@ -0,0 +1,33 @@ +#compdef revolver + +_commands=( + 'start:start the spinner process' + 'update:update the message' + 'stop:stop the spinner process' +) + +### +# Complete revolver commands +### +function _revolver_commands() { + _describe -t commands 'commands' _commands "$@" +} + +### +# Revolver completion +### +function _revolver() { + typeset -A opt_args + local context state line curcontext="$curcontext" + + # Set option arguments + _arguments -A \ + '(-h --help)'{-h,--help}'[show help text and exit]' \ + '(-v --version)'{-v,--version}'[show version information and exit]' + + # Set log level arguments + _arguments \ + '1: :_revolver_commands' +} + +_revolver "$@"