Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use env vars instead of command line args #124

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading