Skip to content

Commit

Permalink
refactor: use env vars instead of command line args (#124)
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Gillson <[email protected]>
  • Loading branch information
TylerGillson committed Aug 14, 2024
1 parent d08775d commit 7dd5858
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions examples/list_clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <host> <apiKey> [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"
}

Expand Down

0 comments on commit 7dd5858

Please sign in to comment.