From 6ec58b685e43ec80ab73723146c43b48a119f12f Mon Sep 17 00:00:00 2001 From: Shohei YOSHIDA Date: Fri, 23 Dec 2022 21:59:58 +0900 Subject: Add cloud subcommand completion --- src/_virtualbox | 198 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 197 insertions(+), 1 deletion(-) (limited to 'src/_virtualbox') diff --git a/src/_virtualbox b/src/_virtualbox index 9edd8d3..33510cb 100644 --- a/src/_virtualbox +++ b/src/_virtualbox @@ -101,7 +101,7 @@ _vboxmanage() { _vboxmanage_encryptvm && ret=0 ;; (cloud) - # TODO + _vboxmanage_cloud && ret=0 ;; (cloudprofile) _vboxmanage_cloudprofile && ret=0 @@ -455,6 +455,202 @@ _vboxmanage_encryptvm_addpassword() { '--new-password-id[specify the new ID for the password for encryption of the VM]:id' } +(( $+functions[_vboxmanage_cloud] )) || +_vboxmanage_cloud() { + local ret=1 + + _arguments -C \ + '1: :(list instance image network)' \ + '*:: :->arg' \ + && ret=0 + + case $state in + (arg) + local subcommand=$words[1] + if (( $+functions[_vboxmanage_cloud_${subcommand}] )); then + _vboxmanage_cloud_${subcommand} && ret=0 + fi + ;; + esac + + return $ret +} + +(( $+functions[_vboxmanage_cloud_list] )) || +_vboxmanage_cloud_list() { + local ret=1 + + _arguments -C \ + '1: :(instances images)' \ + '*:: :->arg' \ + && ret=0 + + case $state in + (arg) + local -a state + if [[ $words[1] == "instances" ]]; then + state=(running paused terminated) + else + state=(available disabled deleted) + fi + + _arguments \ + '--provider=[Short cloud provider name]:provider' \ + '--profile=[Cloud profile name]:profile' \ + '--state=[The state of cloud instance]: :'"($state)" \ + '--compartment-id[A compartment is the logical container used]' + ;; + esac + + return $ret +} + +(( $+functions[_vboxmanage_cloud_instance] )) || +_vboxmanage_cloud_instance() { + local ret=1 + + _arguments -C \ + '1: :(create info termination start pause images)' \ + '*:: :->arg' \ + && ret=0 + + case $state in + (arg) + case $words[1] in + (create) + _arguments \ + '--provider=[Short cloud provider name]:provider' \ + '--profile=[Cloud profile name]:profile' \ + '--domain-name=[Cloud domain where new instance is created]:name' \ + '--image-id=[Unique identifier which fully identifies a custom image in the Cloud]:id' \ + '--boot-volume-id=[Unique identifier which fully identifies a boot volume in the Cloud]:id' \ + '--display-name=[Name for new instance in the Cloud]:name' \ + '--shape=[The shape of instance, defines the number of CPUs and RAM memory]:shape' \ + '--subnet=[Unique identifier which fully identifies an existing subnet]:subnet' \ + '--boot-disk-size=[The size of bootable image in GB]:size' \ + '--publicip=[Whether the instance will have a public IP or not]: :(true false)' \ + '--privateip=[Private IP address for the created instance]:ip' \ + '--public-ssh-key=[Public SSH key used to connect to the instance via SSH]:key' \ + '--launch-mode=[launch mode]: :(EMULATED NATIVE PARAVIRTUALIZED)' \ + '--cloud-init-script-path=[Absolute path to the user cloud-init script]: :_files' \ + && ret=0 + ;; + (*) + _arguments \ + '--provider=[Short cloud provider name]:provider' \ + '--profile=[Cloud profile name]:profile' \ + '--id=[Unique identifier which fully identify the instance in the Cloud]:id' \ + && ret=0 + ;; + esac + ;; + esac + + return $ret +} + +(( $+functions[_vboxmanage_cloud_image] )) || +_vboxmanage_cloud_image() { + local ret=1 + + _arguments -C \ + '1: :(create info delete import export)' \ + '*:: :->arg' \ + && ret=0 + + case $state in + (arg)