Skip to content

Commit

Permalink
Remove os.Exit code
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaesang committed Jul 1, 2022
1 parent 37e4bba commit 3fd9cbf
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 23 deletions.
3 changes: 1 addition & 2 deletions cmd/cluster_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ tks cluster create <CLUSTERNAME>`,
r, err := client.CreateCluster(ctx, &data)
fmt.Println("Response:\n", r)
if err != nil {
fmt.Println("Error:", err)
os.Exit(1)
return fmt.Errorf("Error: %s", err)
} else {
fmt.Println("Success: The request to create cluster ", args[0], " was accepted.")
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/cluster_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ tks cluster delete <CLUSTER_ID>`,
r, err := client.DeleteCluster(ctx, &data)
fmt.Println(r)
if err != nil {
fmt.Println(err)
os.Exit(1)
return fmt.Errorf("Error: %s", err)
} else {
fmt.Println("The request to delete cluster ", args[0], " was accepted.")
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/cluster_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ tks cluster list (--long)`,
}
r, err := client.GetClusters(ctx, &data)
if err != nil {
fmt.Println(err)
os.Exit(1)
return fmt.Errorf("Error: %s", err)
} else {
if len(r.Clusters) == 0 {
fmt.Println("No cluster exists for specified contract!")
Expand Down
3 changes: 1 addition & 2 deletions cmd/cluster_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ tks cluster show <CLUSTER_ID>`,
}
r, err := client.GetCluster(ctx, &data)
if err != nil {
fmt.Println(err)
os.Exit(1)
return fmt.Errorf("Error: %s", err)
} else {
printCluster(r)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/service_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ tks service create --cluster-id <CLUSTERID> --service-name <LMA,LMA_EFK,SERVICE_
r, err := client.InstallAppGroups(ctx, &data[0])
fmt.Println("Response:\n", r)
if err != nil {
fmt.Println("Error:", err)
os.Exit(1)
return fmt.Errorf("Error: %s", err)
} else {
fmt.Println("Success: The request to create service ", AppGroupName, " was accepted.")
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/service_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ tks service delete <SERVICE ID>`,
}
r, err := client.UninstallAppGroups(ctx, &data)
if err != nil {
fmt.Println(err)
os.Exit(1)
return fmt.Errorf("Error: %s", err)
} else {
fmt.Println(r)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/service_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ tks service list <CLUSTER ID> (--long)`,
}
r, err := client.GetAppGroupsByClusterID(ctx, &data)
if err != nil {
fmt.Println(err)
os.Exit(1)
return fmt.Errorf("Error: %s", err)
} else {
long, _ := cmd.Flags().GetBool("long")
printAppGroups(r, long)
Expand Down
14 changes: 5 additions & 9 deletions cmd/show_byoh_agent_guide.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ package cmd

import (
"fmt"
"log"
"os"
"os/exec"

"github.com/spf13/cobra"
Expand All @@ -41,17 +39,15 @@ Standard reference architecture is as follows.
Among these types, the 'worker' nodes might needs to be scaled out based on your application size.
`,
Run: func(cmd *cobra.Command, args []string) {
RunE: func(cmd *cobra.Command, args []string) error {

nodeType, _ := cmd.Flags().GetString("type")
if nodeType == "" {
fmt.Printf("Usage: tks cluster show-byoh-node-agent-guide --type=$NODE_TYPE\n")
os.Exit(1)
return fmt.Errorf("Usage: tks cluster show-byoh-node-agent-guide --type=$NODE_TYPE\n")
}

if nodeType != "controlplane" && nodeType != "tks" && nodeType != "worker" {
fmt.Printf("Wrong node type '%s': please refer to help message.\n", nodeType)
os.Exit(1)
return fmt.Errorf("Wrong node type '%s': please refer to help message.\n", nodeType)
}

fmt.Printf("*************************************************\n")
Expand All @@ -63,7 +59,7 @@ Among these types, the 'worker' nodes might needs to be scaled out based on your
cmdStr := "cat ~/.kube/config | base64"
out, err := exec.Command("bash", "-c", cmdStr).Output()
if err != nil {
log.Fatal(err)
return fmt.Errorf("Error: %s", err)
}

fmt.Printf("Encoded kubeconfig for MGMT cluster:\n%s\n", string(out))
Expand Down Expand Up @@ -98,7 +94,7 @@ That's it! Enjoy BYOH provider!
*******************************
`
fmt.Printf(guide_str, nodeType)

return nil
},
}

Expand Down

0 comments on commit 3fd9cbf

Please sign in to comment.