Skip to content

Commit c634106

Browse files
committed
Change --plan by --hosts and fixes an error on the help poster
Signed-off-by: Gu1llaum-3 <[email protected]>
1 parent 8861d70 commit c634106

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

cmd/reset.go

+11-10
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,19 @@ type Node struct {
1717
}
1818

1919
func MakeReset() *cobra.Command {
20-
var user, ip, sshKey, plan string
20+
var user, ip, sshKey, hosts string
2121

2222
cmd := &cobra.Command{
2323
Use: "reset",
2424
Short: "Uninstall k3s on specified nodes",
2525
RunE: func(cmd *cobra.Command, args []string) error {
26-
if user == "" || (ip == "" && plan == "") {
27-
return fmt.Errorf("Usage: %s", cmd.UsageString())
26+
if user == "" || (ip == "" && hosts == "") {
27+
cmd.Help()
28+
return nil // Change this line to return nil instead of an error
2829
}
2930

30-
if plan != "" {
31-
return uninstallK3sFromPlan(user, sshKey, plan)
31+
if hosts != "" {
32+
return uninstallK3sFromHosts(user, sshKey, hosts)
3233
}
3334
return uninstallK3s(user, sshKey, ip)
3435
},
@@ -37,7 +38,7 @@ func MakeReset() *cobra.Command {
3738
cmd.Flags().StringVarP(&user, "user", "u", "", "Username for SSH connection")
3839
cmd.Flags().StringVarP(&ip, "ip", "i", "", "IP address of the host")
3940
cmd.Flags().StringVar(&sshKey, "ssh-key", os.Getenv("HOME")+"/.ssh/id_rsa", "Path to the private SSH key")
40-
cmd.Flags().StringVar(&plan, "plan", "", "JSON file containing the list of nodes")
41+
cmd.Flags().StringVar(&hosts, "hosts", "", "JSON file containing the list of nodes")
4142

4243
return cmd
4344
}
@@ -65,15 +66,15 @@ fi
6566
return nil
6667
}
6768

68-
func uninstallK3sFromPlan(user, sshKey, plan string) error {
69-
data, err := ioutil.ReadFile(plan)
69+
func uninstallK3sFromHosts(user, sshKey, hosts string) error {
70+
data, err := ioutil.ReadFile(hosts)
7071
if err != nil {
71-
return fmt.Errorf("unable to read JSON file %s: %v", plan, err)
72+
return fmt.Errorf("unable to read JSON file %s: %v", hosts, err)
7273
}
7374

7475
var nodes []Node
7576
if err := json.Unmarshal(data, &nodes); err != nil {
76-
return fmt.Errorf("error parsing JSON file %s: %v", plan, err)
77+
return fmt.Errorf("error parsing JSON file %s: %v", hosts, err)
7778
}
7879

7980
var successNodes []Node

0 commit comments

Comments
 (0)