From a3477c44ff92ba47f2ce6955cf8dc56edacf65d8 Mon Sep 17 00:00:00 2001 From: Giovanni Torres Date: Mon, 20 Nov 2017 11:40:15 -0500 Subject: [PATCH] Avoid deleting directory when not specifying a hostname to create/remove. - Exit when none or two or more hostnames are specified. - Accept help as a subcommand for create and remove. --- kvm-install-vm | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/kvm-install-vm b/kvm-install-vm index 30c738c..49ab350 100755 --- a/kvm-install-vm +++ b/kvm-install-vm @@ -33,11 +33,14 @@ function usage_subcommand () create) cat << EOF NAME - $prog create [OPTIONS] VMNAME + $prog create [COMMANDS] [OPTIONS] VMNAME DESCRIPTION Create a new guest domain. +COMMANDS + help - show this help + OPTIONS -b Bridge (default: virbr0) -c Number of vCPUs (default: 1) @@ -83,12 +86,15 @@ EOF remove) cat << EOF NAME - $prog remove VMNAME + $prog remove [COMMANDS] VMNAME DESCRIPTION Destroys (stops) and undefines a guest domain. This also remove the associated storage pool. +COMMANDS + help - show this help + EXAMPLE $prog remove foo Remove (destroy and undefine) a guest domain. WARNING: This will @@ -520,7 +526,9 @@ function create () if [ "$#" != 1 ] then - printf "Too many options.\n" + printf "Please specify a single host to create.\n" + printf "Run 'kvm-install-vm help create' for usage.\n" + exit 1 else VMNAME=$1 fi @@ -595,8 +603,16 @@ case "${subcommand}" in exit 0 ;; create|remove) - "${subcommand}" "$@" - exit $? + if [[ "${1:-none}" == "none" ]]; then + usage_subcommand "${subcommand}" + exit 1 + elif [[ "$1" =~ ^help$ ]]; then + usage_subcommand "${subcommand}" + exit 1 + else + "${subcommand}" "$@" + exit $? + fi ;; *) echo "not valid"