diff --git a/scripts/completion.bash b/scripts/completion.bash new file mode 100644 index 0000000..cbeab4a --- /dev/null +++ b/scripts/completion.bash @@ -0,0 +1,107 @@ +#!/usr/bin/env bash + +# Tasks need some formatting. +fetch_task_list() ( + placeos task --list 2>/dev/null | grep --extended-regexp '^\w+[\: ].*\|' | sed -E 's/ +/ /g' | cut -d' ' -f1 +) + +_placeos() { + local cur prev + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + + case "${prev}" in + placeos) + case "${cur}" in + -*) + COMPREPLY=( $(compgen -W " + -h --help + " -- ${cur}) ) + ;; + *) + COMPREPLY=( $(compgen -W " + start + stop + task + changelog + update + upgrade + uninstall + version + help + " -- ${cur}) ) + ;; + esac + ;; + start) + case ${cur} in + -*) + COMPREPLY=( $(compgen -W " + --email + --password + --application + --domain + --hard-reset + -v --verbose + -h --help + " -- ${cur}) ) + ;; + esac + ;; + stop) + case ${cur} in + -*) + COMPREPLY=( $(compgen -W "-v --verbose -h --help" -- ${cur}) ) + ;; + esac + ;; + task) + case ${cur} in + -*) + COMPREPLY=( $(compgen -W "--list -h --help" -- ${cur}) ) + ;; + *) + COMPREPLY=( $(compgen -W "$(fetch_task_list)" -- ${cur}) ) + ;; + esac + ;; + changelog) + case ${cur} in + -*) + COMPREPLY=( $(compgen -W "--full -h --help" -- ${cur}) ) + ;; + esac + ;; + update) + case ${cur} in + -*) + COMPREPLY=( $(compgen -W "--list --restart -v --verbose -h --help" -- ${cur}) ) + ;; + *) + COMPREPLY=( $(compgen -W "$(placeos update --list)" -- ${cur}) ) + ;; + esac + ;; + upgrade) + case ${cur} in + -*) + COMPREPLY=( $(compgen -W "--list -q --quiet -h --help" -- ${cur}) ) + ;; + *) + COMPREPLY=( $(compgen -W "$(placeos upgrade --list)" -- ${cur}) ) + ;; + esac + ;; + uninstall) + case ${cur} in + -*) + COMPREPLY=( $(compgen -W "--force -h --help" -- ${cur}) ) + ;; + esac + ;; + esac + return 0 +} + +complete -F _placeos placeos diff --git a/scripts/completion.zsh b/scripts/completion.zsh new file mode 100644 index 0000000..23f3d5d --- /dev/null +++ b/scripts/completion.zsh @@ -0,0 +1,110 @@ +#compdef placeos + +_placeos() { + +_placeos_commands() { + local -a commmands; commands=( + 'start:start the environment.' \ + 'stop:stops the environment.' \ + 'task:runs a task in the environment.' \ + 'changelog:displays platform changelog (in markdown).' \ + 'update:update the platform version.' \ + 'upgrade:upgrade the Partner Environment.' \ + 'uninstall:uninstalls the Partner Environment.' \ + 'help:display this message.' \ + ) + _describe -t commands 'PlaceOS commmand' commands +} + + +local -a _start_arguments; _start_arguments=( + '--email:email to setup an admin account for.' \ + '--password:password for created admin account.' \ + '--application:application to configure.' \ + '--domain:domain to configure.' \ + '--hard-reset:reset the environment to a default state.' \ + $verbose_args \ + $help_args \ +) + +local -a help_args; help_args=( + '(-h --help)[show help]' +) + +local -a verbose_args; verbose_args=( + '(-v --verbose)'{-v,--verbose}'[write logs to STDOUT in addition to the log file]' +) + +local -a _stop_arguments; _stop_arguments=( + $verbose_args \ + $help_args \ +) + +local -a _task_arguments; _task_arguments=( + '-t:--tasks:display list of available tasks.' \ + $help_args \ +) + +local -a _changelog_arguments; _changelog_arguments=( + '--full:include all prior CHANGELOG entries.' \ + $help_args \ +) + +local -a _update_arguments; _update_arguments=( + '--list:list the available versions.' \ + $verbose_args \ + $help_args \ +) + +local -a _upgrade_arguments; _upgrade_arguments=( + '--list:lists versions of the Partner Environment.' \ + '-q:do not write command logs to STDOUT.' \ + $help_args \ +) + +local -a _uninstall_arguments; _uninstall_arguments=( + '--force:skip confirmation of uninstall.' \ + $help_args \ +) + +_arguments -C \ + '1: :->subcommand' \ + '*:: :->task' && return 0 + +case $state in + (subcommand) + _placeos_commands && return 0 + ;; + (task) + case $line[1] in + (start) + _describe -t commands 'PlaceOS start task' _start_arguments && return 0 + ;; + (stop) + _describe -t commands 'PlaceOS stop task' _stop_arguments && return 0 + ;; + (task) + _describe -t commands 'PlaceOS task task' _task_arguments && return 0 + ;; + (changelog) + _describe -t commands 'PlaceOS changelog task' _changelog_arguments && return 0 + ;; + (update) + _describe -t commands 'PlaceOS update task' _update_arguments && return 0 + ;; + (upgrade) + _describe -t commands 'PlaceOS upgrade task' _upgrade_arguments && return 0 + ;; + (uninstall) + _describe -t commands 'PlaceOS uninstall task' _uninstall_arguments && return 0 + ;; + (help) + _describe -t commands 'PlaceOS help task' _help_arguments && return 0 + ;; + esac + ;; +esac + +} + +_placeos