From 26626134a529a1e00c618b90f2f63204b775b4d6 Mon Sep 17 00:00:00 2001 From: Tyler Gillson Date: Wed, 14 Aug 2024 08:55:08 -0600 Subject: [PATCH] refactor: use env vars instead of command line args Signed-off-by: Tyler Gillson --- examples/list_clusters.go | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/examples/list_clusters.go b/examples/list_clusters.go index b813a57a..45809780 100644 --- a/examples/list_clusters.go +++ b/examples/list_clusters.go @@ -9,21 +9,19 @@ import ( ) func main() { - var host, apiKey, projectUid, scope string - // Parse command line arguments + // Read environment variables - numArgs := len(os.Args) - if numArgs < 3 || numArgs > 4 { - fmt.Println("Usage: main [projectUid]") + host := os.Getenv("PALETTE_HOST") + apiKey := os.Getenv("PALETTE_API_KEY") + projectUid := os.Getenv("PALETTE_PROJECT_UID") + scope := "tenant" + + if host == "" || apiKey == "" { + fmt.Println("You must specify the PALETTE_HOST and PALETTE_API_KEY environment variables.") os.Exit(1) } - switch numArgs { - case 3: - host, apiKey = os.Args[1], os.Args[2] - scope = "tenant" - case 4: - host, apiKey, projectUid = os.Args[1], os.Args[2], os.Args[3] + if projectUid != "" { scope = "project" }