From 7efc8506af4e78cce6379bd591b3d8c1cb5d0260 Mon Sep 17 00:00:00 2001 From: Caspian Baska Date: Sat, 23 Apr 2022 12:09:44 +1000 Subject: [PATCH 1/6] feat(placeos): add draft of completion --- scripts/completion | 183 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 183 insertions(+) create mode 100644 scripts/completion diff --git a/scripts/completion b/scripts/completion new file mode 100644 index 0000000..9129ec5 --- /dev/null +++ b/scripts/completion @@ -0,0 +1,183 @@ +#! /usr/bin/env bash + +_placeos_comp() { + local cur_="${3-$cur}" + local possible="grep "^${cur_}"<<<${1})" + + case "$cur_" in + --*=) ;; + + *) + local c i=0 IFS=$' \t\n' + for c in $possible; do + c="$c${4-}" + if [[ $c == "$cur_"* ]]; then + case $c in + --*=* | *.) ;; + *) c="$c " ;; + esac + COMPREPLY[i++]="${2-}$c" + fi + done + ;; + esac +} + +_placeos_start() { + case "$cur" in + -*) + __placeos_comp " + -v + -h + --verbose + --help + --hard-reset + --email + --password + --domain + --application + --analytics + --kibana + " + return + ;; + esac +} + +_placeos_stop() { + case "$cur" in + -*) + __placeos_comp " + -v + -h + --verbose + --help + " + return + ;; + esac +} + +_placeos_task() { + case "$cur" in + -*) + __placeos_comp " + -h + --help + -t + --tasks + " + return + ;; + *) + __placeos_comp "$(placeos task --tasks)" + return + ;; + esac +} + +_placeos_update() { + + case "$cur" in + -*) + __placeos_comp " + -h + --help + -v + --verbose + --list + " + return + ;; + *) + __placeos_comp "$(placeos update --list)" + return + ;; + esac +} + +_placeos_upgrade() { + case "$cur" in + -*) + __placeos_comp " + -h + --help + -v + --verbose + --list + " + return + ;; + *) + __placeos_comp "$(placeos upgrade --list)" + return + ;; + esac +} + +_placeos_uninstall() { + case "$cur" in + -*) + __placeos_comp " + -h + --help + --force + " + return + ;; + esac +} + +# Plumbing +################################################################################################### + +_placeos() { + local cur prev opts + + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD - 1]}" + words=("${COMP_WORDS[@]}") + cword=$COMP_CWORD + + echo $cur + echo $prev + echo $words + + case ${COMP_CWORD} in + 1) + __placeos_comp " + start + stop + update + upgrade + task + " + ;; + 2) + case ${prev} in + -*) ;; + + start) + _placeos_start + ;; + stop) + _placeos_stop + ;; + update) + _placeos_update + ;; + upgrade) + _placeos_upgrade + ;; + task) + _placeos_task + ;; + esac + ;; + esac + + return 0 +} + +complete -F _placeos placeos From 52450ac413e2f8908f9e2de82cd7371e97759abf Mon Sep 17 00:00:00 2001 From: Caspian Baska Date: Tue, 26 Apr 2022 08:15:35 +1000 Subject: [PATCH 2/6] feat: add GPT3 drafts of completion --- gpt3-attempt.bash | 95 +++++++++++++++++++++ gpt3-attempt.zsh | 106 ++++++++++++++++++++++++ scripts/{completion => completion.bash} | 4 +- scripts/completion.zsh | 100 ++++++++++++++++++++++ 4 files changed, 303 insertions(+), 2 deletions(-) create mode 100644 gpt3-attempt.bash create mode 100644 gpt3-attempt.zsh rename scripts/{completion => completion.bash} (97%) create mode 100644 scripts/completion.zsh diff --git a/gpt3-attempt.bash b/gpt3-attempt.bash new file mode 100644 index 0000000..f856cf4 --- /dev/null +++ b/gpt3-attempt.bash @@ -0,0 +1,95 @@ +#!/usr/bin/env bash + +PLACEOS_RELEASE_REPO="PlaceOS/PlaceOS" + +CALVER_FULL_REGEX='[0-9]+\.[0-9]{4}\.[0-9]+(-rc[0-9]+)?' +CALVER_MONTH_REGEX='[0-9]+\.[0-9]{4}' +VERSION_CHANNEL_REGEX='(nightly|preview|latest)' + +fetch_release_tags() ( + git ls-remote https://github.com/${PLACEOS_RELEASE_REPO} | + cut -f2 | + grep '^refs/tags/' | + cut -d'/' -f3 | + sort --version-sort --reverse | + sed -E "s/($CALVER_FULL_REGEX|$CALVER_MONTH_REGEX)/placeos-\1/g" +) + + +_placeos() { + local cur prev + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + + if [[ ${prev} == placeos ]]; then + COMPREPLY=( $(compgen -W "start stop task changelog update upgrade uninstall help" -- ${cur}) ) + return 0 + fi + + case "${prev}" in + 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 "-t --tasks -h --help" -- ${cur}) ) + ;; + esac + ;; + changelog) + case ${cur} in + -*) + COMPREPLY=( $(compgen -W "--full -h --help" -- ${cur}) ) + ;; + esac + ;; + update) + case ${cur} in + -*) + COMPREPLY=( $(compgen -W "--restart -v --verbose -h --help" -- ${cur}) ) + ;; + *) + COMPREPLY=( $(compgen -W "$(fetch_release_tags)" -- ${cur}) ) + ;; + esac + ;; + upgrade) + case ${cur} in + -*) + COMPREPLY=( $(compgen -W "--list -q --quiet -h --help" -- ${cur}) ) + ;; + esac + ;; + uninstall) + case ${cur} in + -*) + COMPREPLY=( $(compgen -W "--force -h --help" -- ${cur}) ) + ;; + esac + ;; + esac + return 0 +} + +complete -F _placeos placeos diff --git a/gpt3-attempt.zsh b/gpt3-attempt.zsh new file mode 100644 index 0000000..751a61a --- /dev/null +++ b/gpt3-attempt.zsh @@ -0,0 +1,106 @@ +```zsh +#compdef placeos + +_placeos() { + typeset -A opt_args + local context state line + context=(-1 CATEGORY) + _arguments \ + '1: :->command' \ + '*:: :->args' && return 0 + + case $state in + (command) + _arguments \ + '1: :->command' \ + '*:: :->args' && return 0 + ;; + (args) + case $line[1] in + (start) + _arguments \ + '1: :->start' \ + '*:: :->start' && return 0 + ;; + (stop) + _arguments \ + '1: :->stop' \ + '*:: :->stop' && return 0 + ;; + (task) + _arguments \ + '1: :->task' \ + '*:: :->task' && return 0 + ;; + (changelog) + _arguments \ + '1: :->changelog' \ + '*:: :->changelog' && return 0 + ;; + (update) + _arguments \ + '1: :->update' \ + '*:: :->update' && return 0 + ;; + (upgrade) + _arguments \ + '1: :->upgrade' \ + '*:: :->upgrade' && return 0 + ;; + (uninstall) + _arguments \ + '1: :->uninstall' \ + '*:: :->uninstall' && return 0 + ;; + (help) + _arguments \ + '1: :->help' \ + '*:: :->help' && return 0 + ;; + esac + ;; + (start) + _arguments \ + '1: :->start' \ + '*:: :->start' && return 0 + ;; + (stop) + _arguments \ + '1: :->stop' \ + '*:: :->stop' && return 0 + ;; + (task) + _arguments \ + '1: :->task' \ + '*:: :->task' && return 0 + ;; + (changelog) + _arguments \ + '1: :->changelog' \ + '*:: :->changelog' && return 0 + ;; + (update) + _arguments \ + '1: :->update' \ + '*:: :->update' && return 0 + ;; + (upgrade) + _arguments \ + '1: :->upgrade' \ + '*:: :->upgrade' && return 0 + ;; + (uninstall) + _arguments \ + '1: :->uninstall' \ + '*:: :->uninstall' && return 0 + ;; + (help) + _arguments \ + '1: :->help' \ + '*:: :->help' && return 0 + ;; + esac +} + +_placeos "$@" +``` diff --git a/scripts/completion b/scripts/completion.bash similarity index 97% rename from scripts/completion rename to scripts/completion.bash index 9129ec5..a3537c6 100644 --- a/scripts/completion +++ b/scripts/completion.bash @@ -1,8 +1,8 @@ #! /usr/bin/env bash -_placeos_comp() { +__placeos_comp() { local cur_="${3-$cur}" - local possible="grep "^${cur_}"<<<${1})" + local possible="$(grep "^${cur_}"<<<${1})" case "$cur_" in --*=) ;; diff --git a/scripts/completion.zsh b/scripts/completion.zsh new file mode 100644 index 0000000..0fa9508 --- /dev/null +++ b/scripts/completion.zsh @@ -0,0 +1,100 @@ +#compdef placeos + +local -a _1st_arguments +_1st_arguments=( + '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.' +) + +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.' + '-v:Write logs to STDOUT in addition to the log file.' + 'h:Display this message' +) + +local -a _stop_arguments +_stop_arguments=( + '-v:Write logs to STDOUT in addition to the log file.' + '-h:Display this message.' +) + +local -a _task_arguments +_task_arguments=( + '-t:--tasks:Display list of available tasks.' + '-h:Display this message.' +) + +local -a _changelog_arguments +_changelog_arguments=( + '--full:Include all prior CHANGELOG entries.' + '-h:Display this message' +) + +local -a _update_arguments +_update_arguments=( + '--list:List the available versions.' + '-v:--verbose:Write logs to STDOUT in addition to the log file.' + '-h:Display this message.' +) + +local -a _upgrade_arguments +_upgrade_arguments=( + '--list:Lists versions of the Partner Environment.' + '-q:Do not write command logs to STDOUT.' + '-h:Display this message.' +) + +local -a _uninstall_arguments +_uninstall_arguments=( + '--force:Skip confirmation of uninstall.' + '-h:Display this message.' +) + +_arguments -C \ + '1: :->subcommand' \ + '*:: :->task' && return 0 + +case $state in + (subcommand) + _describe -t commands 'PlaceOS subcommand' _1st_arguments && 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- From d1855b4d747e400a42f0c956316f9cb3909ec657 Mon Sep 17 00:00:00 2001 From: Caspian Baska Date: Tue, 26 Apr 2022 20:26:57 +1000 Subject: [PATCH 3/6] feat: add completion for tasks, and environment versions --- gpt3-attempt.bash | 95 -------------- scripts/completion.bash | 276 ++++++++++++++++------------------------ 2 files changed, 111 insertions(+), 260 deletions(-) delete mode 100644 gpt3-attempt.bash diff --git a/gpt3-attempt.bash b/gpt3-attempt.bash deleted file mode 100644 index f856cf4..0000000 --- a/gpt3-attempt.bash +++ /dev/null @@ -1,95 +0,0 @@ -#!/usr/bin/env bash - -PLACEOS_RELEASE_REPO="PlaceOS/PlaceOS" - -CALVER_FULL_REGEX='[0-9]+\.[0-9]{4}\.[0-9]+(-rc[0-9]+)?' -CALVER_MONTH_REGEX='[0-9]+\.[0-9]{4}' -VERSION_CHANNEL_REGEX='(nightly|preview|latest)' - -fetch_release_tags() ( - git ls-remote https://github.com/${PLACEOS_RELEASE_REPO} | - cut -f2 | - grep '^refs/tags/' | - cut -d'/' -f3 | - sort --version-sort --reverse | - sed -E "s/($CALVER_FULL_REGEX|$CALVER_MONTH_REGEX)/placeos-\1/g" -) - - -_placeos() { - local cur prev - COMPREPLY=() - cur="${COMP_WORDS[COMP_CWORD]}" - prev="${COMP_WORDS[COMP_CWORD-1]}" - - if [[ ${prev} == placeos ]]; then - COMPREPLY=( $(compgen -W "start stop task changelog update upgrade uninstall help" -- ${cur}) ) - return 0 - fi - - case "${prev}" in - 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 "-t --tasks -h --help" -- ${cur}) ) - ;; - esac - ;; - changelog) - case ${cur} in - -*) - COMPREPLY=( $(compgen -W "--full -h --help" -- ${cur}) ) - ;; - esac - ;; - update) - case ${cur} in - -*) - COMPREPLY=( $(compgen -W "--restart -v --verbose -h --help" -- ${cur}) ) - ;; - *) - COMPREPLY=( $(compgen -W "$(fetch_release_tags)" -- ${cur}) ) - ;; - esac - ;; - upgrade) - case ${cur} in - -*) - COMPREPLY=( $(compgen -W "--list -q --quiet -h --help" -- ${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.bash b/scripts/completion.bash index a3537c6..bcc6a2a 100644 --- a/scripts/completion.bash +++ b/scripts/completion.bash @@ -1,182 +1,128 @@ -#! /usr/bin/env bash - -__placeos_comp() { - local cur_="${3-$cur}" - local possible="$(grep "^${cur_}"<<<${1})" - - case "$cur_" in - --*=) ;; - - *) - local c i=0 IFS=$' \t\n' - for c in $possible; do - c="$c${4-}" - if [[ $c == "$cur_"* ]]; then - case $c in - --*=* | *.) ;; - *) c="$c " ;; - esac - COMPREPLY[i++]="${2-}$c" - fi - done - ;; - esac -} - -_placeos_start() { - case "$cur" in - -*) - __placeos_comp " - -v - -h - --verbose - --help - --hard-reset - --email - --password - --domain - --application - --analytics - --kibana - " - return - ;; - esac -} - -_placeos_stop() { - case "$cur" in - -*) - __placeos_comp " - -v - -h - --verbose - --help - " - return - ;; - esac -} - -_placeos_task() { - case "$cur" in - -*) - __placeos_comp " - -h - --help - -t - --tasks - " - return - ;; - *) - __placeos_comp "$(placeos task --tasks)" - return - ;; - esac -} - -_placeos_update() { - - case "$cur" in - -*) - __placeos_comp " - -h - --help - -v - --verbose - --list - " - return - ;; - *) - __placeos_comp "$(placeos update --list)" - return - ;; - esac -} - -_placeos_upgrade() { - case "$cur" in - -*) - __placeos_comp " - -h - --help - -v - --verbose - --list - " - return - ;; - *) - __placeos_comp "$(placeos upgrade --list)" - return - ;; - esac -} - -_placeos_uninstall() { - case "$cur" in - -*) - __placeos_comp " - -h - --help - --force - " - return - ;; - esac -} - -# Plumbing -################################################################################################### +#!/usr/bin/env bash + +PLACEOS_RELEASE_REPO="PlaceOS/PlaceOS" +CALVER_FULL_REGEX='[0-9]+\.[0-9]{4}\.[0-9]+(-rc[0-9]+)?' +CALVER_MONTH_REGEX='[0-9]+\.[0-9]{4}' + +fetch_release_tags() ( + git ls-remote https://github.com/${PLACEOS_RELEASE_REPO} | + cut -f2 | + grep '^refs/tags/' | + cut -d'/' -f3 | + sort --version-sort --reverse | + sed -E "s/($CALVER_FULL_REGEX|$CALVER_MONTH_REGEX)/placeos-\1/g" +) + +PARTNER_ENV_REPO="placeos/partner-environment" + +fetch_environment_tags() ( + git ls-remote https://github.com/${PARTNER_ENV_REPO} | + cut -f2 | + grep --extended-regexp '^refs/tags/|HEAD' | + cut -d'/' -f3 | + sort --version-sort --reverse +) + +fetch_task_list() ( + placeos task --list 2>/dev/null | grep --extended-regexp '^\w+[\: ].*\|' | sed -E 's/ +/ /g' | cut -d' ' -f1 +) _placeos() { - local cur prev opts - + local cur prev COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" - prev="${COMP_WORDS[COMP_CWORD - 1]}" - words=("${COMP_WORDS[@]}") - cword=$COMP_CWORD - - echo $cur - echo $prev - echo $words - - case ${COMP_CWORD} in - 1) - __placeos_comp " - start - stop - update - upgrade - task - " - ;; - 2) - case ${prev} in - -*) ;; - + 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) - _placeos_start + case ${cur} in + -*) + COMPREPLY=( $(compgen -W " + --email + --password + --application + --domain + --hard-reset + -v --verbose + -h --help + " -- ${cur}) ) + ;; + esac ;; stop) - _placeos_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) - _placeos_update + case ${cur} in + -*) + COMPREPLY=( $(compgen -W "--restart -v --verbose -h --help" -- ${cur}) ) + ;; + *) + COMPREPLY=( $(compgen -W "$(fetch_release_tags)" -- ${cur}) ) + ;; + esac ;; upgrade) - _placeos_upgrade + case ${cur} in + -*) + COMPREPLY=( $(compgen -W "--list -q --quiet -h --help" -- ${cur}) ) + ;; + *) + COMPREPLY=( $(compgen -W "$(fetch_environment_tags)" -- ${cur}) ) + ;; + esac ;; - task) - _placeos_task + uninstall) + case ${cur} in + -*) + COMPREPLY=( $(compgen -W "--force -h --help" -- ${cur}) ) + ;; + esac ;; - esac - ;; esac - return 0 } From 5a32c49277da20c3d63aaa790e7ef9b86b070276 Mon Sep 17 00:00:00 2001 From: Caspian Baska Date: Tue, 26 Apr 2022 20:27:36 +1000 Subject: [PATCH 4/6] chore: remove busted openapi zsh completion --- gpt3-attempt.zsh | 106 ----------------------------------------------- 1 file changed, 106 deletions(-) delete mode 100644 gpt3-attempt.zsh diff --git a/gpt3-attempt.zsh b/gpt3-attempt.zsh deleted file mode 100644 index 751a61a..0000000 --- a/gpt3-attempt.zsh +++ /dev/null @@ -1,106 +0,0 @@ -```zsh -#compdef placeos - -_placeos() { - typeset -A opt_args - local context state line - context=(-1 CATEGORY) - _arguments \ - '1: :->command' \ - '*:: :->args' && return 0 - - case $state in - (command) - _arguments \ - '1: :->command' \ - '*:: :->args' && return 0 - ;; - (args) - case $line[1] in - (start) - _arguments \ - '1: :->start' \ - '*:: :->start' && return 0 - ;; - (stop) - _arguments \ - '1: :->stop' \ - '*:: :->stop' && return 0 - ;; - (task) - _arguments \ - '1: :->task' \ - '*:: :->task' && return 0 - ;; - (changelog) - _arguments \ - '1: :->changelog' \ - '*:: :->changelog' && return 0 - ;; - (update) - _arguments \ - '1: :->update' \ - '*:: :->update' && return 0 - ;; - (upgrade) - _arguments \ - '1: :->upgrade' \ - '*:: :->upgrade' && return 0 - ;; - (uninstall) - _arguments \ - '1: :->uninstall' \ - '*:: :->uninstall' && return 0 - ;; - (help) - _arguments \ - '1: :->help' \ - '*:: :->help' && return 0 - ;; - esac - ;; - (start) - _arguments \ - '1: :->start' \ - '*:: :->start' && return 0 - ;; - (stop) - _arguments \ - '1: :->stop' \ - '*:: :->stop' && return 0 - ;; - (task) - _arguments \ - '1: :->task' \ - '*:: :->task' && return 0 - ;; - (changelog) - _arguments \ - '1: :->changelog' \ - '*:: :->changelog' && return 0 - ;; - (update) - _arguments \ - '1: :->update' \ - '*:: :->update' && return 0 - ;; - (upgrade) - _arguments \ - '1: :->upgrade' \ - '*:: :->upgrade' && return 0 - ;; - (uninstall) - _arguments \ - '1: :->uninstall' \ - '*:: :->uninstall' && return 0 - ;; - (help) - _arguments \ - '1: :->help' \ - '*:: :->help' && return 0 - ;; - esac -} - -_placeos "$@" -``` From d5408df3327403713dd83488bba616a94429274b Mon Sep 17 00:00:00 2001 From: Caspian Baska Date: Wed, 27 Apr 2022 00:35:34 +1000 Subject: [PATCH 5/6] feat(completion): use placeos script --- scripts/completion.bash | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/scripts/completion.bash b/scripts/completion.bash index bcc6a2a..cbeab4a 100644 --- a/scripts/completion.bash +++ b/scripts/completion.bash @@ -1,28 +1,6 @@ #!/usr/bin/env bash -PLACEOS_RELEASE_REPO="PlaceOS/PlaceOS" -CALVER_FULL_REGEX='[0-9]+\.[0-9]{4}\.[0-9]+(-rc[0-9]+)?' -CALVER_MONTH_REGEX='[0-9]+\.[0-9]{4}' - -fetch_release_tags() ( - git ls-remote https://github.com/${PLACEOS_RELEASE_REPO} | - cut -f2 | - grep '^refs/tags/' | - cut -d'/' -f3 | - sort --version-sort --reverse | - sed -E "s/($CALVER_FULL_REGEX|$CALVER_MONTH_REGEX)/placeos-\1/g" -) - -PARTNER_ENV_REPO="placeos/partner-environment" - -fetch_environment_tags() ( - git ls-remote https://github.com/${PARTNER_ENV_REPO} | - cut -f2 | - grep --extended-regexp '^refs/tags/|HEAD' | - cut -d'/' -f3 | - sort --version-sort --reverse -) - +# Tasks need some formatting. fetch_task_list() ( placeos task --list 2>/dev/null | grep --extended-regexp '^\w+[\: ].*\|' | sed -E 's/ +/ /g' | cut -d' ' -f1 ) @@ -98,10 +76,10 @@ _placeos() { update) case ${cur} in -*) - COMPREPLY=( $(compgen -W "--restart -v --verbose -h --help" -- ${cur}) ) + COMPREPLY=( $(compgen -W "--list --restart -v --verbose -h --help" -- ${cur}) ) ;; *) - COMPREPLY=( $(compgen -W "$(fetch_release_tags)" -- ${cur}) ) + COMPREPLY=( $(compgen -W "$(placeos update --list)" -- ${cur}) ) ;; esac ;; @@ -111,7 +89,7 @@ _placeos() { COMPREPLY=( $(compgen -W "--list -q --quiet -h --help" -- ${cur}) ) ;; *) - COMPREPLY=( $(compgen -W "$(fetch_environment_tags)" -- ${cur}) ) + COMPREPLY=( $(compgen -W "$(placeos upgrade --list)" -- ${cur}) ) ;; esac ;; From 03c4b0a15882f08ccfaf65600dd6c3f382d8a0db Mon Sep 17 00:00:00 2001 From: Caspian Baska Date: Wed, 27 Apr 2022 12:26:03 +1000 Subject: [PATCH 6/6] feat: further work on zsh completion --- scripts/completion.zsh | 104 ++++++++++++++++++++++------------------- 1 file changed, 57 insertions(+), 47 deletions(-) diff --git a/scripts/completion.zsh b/scripts/completion.zsh index 0fa9508..23f3d5d 100644 --- a/scripts/completion.zsh +++ b/scripts/completion.zsh @@ -1,64 +1,70 @@ #compdef placeos -local -a _1st_arguments -_1st_arguments=( - '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.' +_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 _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.' - '-v:Write logs to STDOUT in addition to the log file.' - 'h:Display this message' +local -a help_args; help_args=( + '(-h --help)[show help]' ) -local -a _stop_arguments -_stop_arguments=( - '-v:Write logs to STDOUT in addition to the log file.' - '-h:Display this message.' +local -a verbose_args; verbose_args=( + '(-v --verbose)'{-v,--verbose}'[write logs to STDOUT in addition to the log file]' ) -local -a _task_arguments -_task_arguments=( - '-t:--tasks:Display list of available tasks.' - '-h:Display this message.' +local -a _stop_arguments; _stop_arguments=( + $verbose_args \ + $help_args \ ) -local -a _changelog_arguments -_changelog_arguments=( - '--full:Include all prior CHANGELOG entries.' - '-h:Display this message' +local -a _task_arguments; _task_arguments=( + '-t:--tasks:display list of available tasks.' \ + $help_args \ ) -local -a _update_arguments -_update_arguments=( - '--list:List the available versions.' - '-v:--verbose:Write logs to STDOUT in addition to the log file.' - '-h:Display this message.' +local -a _changelog_arguments; _changelog_arguments=( + '--full:include all prior CHANGELOG entries.' \ + $help_args \ ) -local -a _upgrade_arguments -_upgrade_arguments=( - '--list:Lists versions of the Partner Environment.' - '-q:Do not write command logs to STDOUT.' - '-h:Display this message.' +local -a _update_arguments; _update_arguments=( + '--list:list the available versions.' \ + $verbose_args \ + $help_args \ ) -local -a _uninstall_arguments -_uninstall_arguments=( - '--force:Skip confirmation of uninstall.' - '-h:Display this message.' +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 \ @@ -67,7 +73,7 @@ _arguments -C \ case $state in (subcommand) - _describe -t commands 'PlaceOS subcommand' _1st_arguments && return 0 + _placeos_commands && return 0 ;; (task) case $line[1] in @@ -97,4 +103,8 @@ case $state in ;; esac ;; -esac- +esac + +} + +_placeos