From 6c7bd6b09615f149cb1de34ed8e149d7b4b8ae53 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 5 Jan 2024 21:18:31 -0600 Subject: [PATCH] Refactor script to organize commands into functions - Created a new function: 'auth' - 'auth' is dedicated to the 'login' command - Modified 'rootUsage' to direct to these new functions based on user input - Updated help message to reflect the new command structure --- src/azure/{ => auth}/Login.sh | 0 src/azure/auth/driver.sh | 26 +++++++++++++++++++ src/azure/auth/loadScripts.sh | 2 ++ .../{credentialDriver.sh => driver.sh} | 0 src/azure/credential/loadScripts.sh | 2 +- src/azure/driver.sh | 20 +++++++------- src/azure/loadScripts.sh | 2 +- 7 files changed, 39 insertions(+), 13 deletions(-) rename src/azure/{ => auth}/Login.sh (100%) create mode 100644 src/azure/auth/driver.sh create mode 100644 src/azure/auth/loadScripts.sh rename src/azure/credential/{credentialDriver.sh => driver.sh} (100%) diff --git a/src/azure/Login.sh b/src/azure/auth/Login.sh similarity index 100% rename from src/azure/Login.sh rename to src/azure/auth/Login.sh diff --git a/src/azure/auth/driver.sh b/src/azure/auth/driver.sh new file mode 100644 index 00000000..44c42c0e --- /dev/null +++ b/src/azure/auth/driver.sh @@ -0,0 +1,26 @@ +authUsage() { + echo "Usage: $0 credential [command]" + echo "Commands:" + echo " login - Login azure as service-principal" + exit 1 +} + +function auth(){ + + # Check if at least one argument is provided + if [ $# -eq 0 ]; then + authUsage + fi + + # Execute the appropriate command + case "$1" in + login) + login + ;; + *) + echo "Error: Invalid command." + authUsage + ;; + esac + +} \ No newline at end of file diff --git a/src/azure/auth/loadScripts.sh b/src/azure/auth/loadScripts.sh new file mode 100644 index 00000000..2a815f46 --- /dev/null +++ b/src/azure/auth/loadScripts.sh @@ -0,0 +1,2 @@ +source auth/Login.sh +source auth/driver.sh \ No newline at end of file diff --git a/src/azure/credential/credentialDriver.sh b/src/azure/credential/driver.sh similarity index 100% rename from src/azure/credential/credentialDriver.sh rename to src/azure/credential/driver.sh diff --git a/src/azure/credential/loadScripts.sh b/src/azure/credential/loadScripts.sh index 2a388494..13013aa4 100644 --- a/src/azure/credential/loadScripts.sh +++ b/src/azure/credential/loadScripts.sh @@ -1,4 +1,4 @@ -source credential/credentialDriver.sh +source credential/driver.sh source credential/SetupCred.sh source credential/ShowCreds.sh source credential/UpdateCreds.sh diff --git a/src/azure/driver.sh b/src/azure/driver.sh index 11673f47..3476f1ae 100644 --- a/src/azure/driver.sh +++ b/src/azure/driver.sh @@ -3,19 +3,17 @@ source config.sh source loadScripts.sh -usage() { - echo "Usage: $0 [command]" - echo "Commands:" - echo " init - Initialize and store new credentials" - echo " update - Update existing credentials" - echo " show - Display current credentials" - echo " login - Login azure as service-principal" +rootUsage() { + echo "Usage: $0 [command group] [command]" + echo "Command groups:" + echo " credential - Manage credentials (init, update, show)" + echo " auth - Authentication management (login)" exit 1 } # Check if at least one argument is provided if [ $# -eq 0 ]; then - usage + rootUsage fi # Execute the appropriate command @@ -23,11 +21,11 @@ case "$1" in credential) credential "$2" ;; - login) - login + auth) + auth "$2" ;; *) echo "Error: Invalid command." - usage + rootUsage ;; esac diff --git a/src/azure/loadScripts.sh b/src/azure/loadScripts.sh index fe8f0013..59b8675f 100644 --- a/src/azure/loadScripts.sh +++ b/src/azure/loadScripts.sh @@ -1,3 +1,3 @@ source credential/loadScripts.sh +source auth/loadScripts.sh -source Login.sh