@@ -17,18 +17,19 @@ type Node struct {
17
17
}
18
18
19
19
func MakeReset () * cobra.Command {
20
- var user , ip , sshKey , plan string
20
+ var user , ip , sshKey , hosts string
21
21
22
22
cmd := & cobra.Command {
23
23
Use : "reset" ,
24
24
Short : "Uninstall k3s on specified nodes" ,
25
25
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
28
29
}
29
30
30
- if plan != "" {
31
- return uninstallK3sFromPlan (user , sshKey , plan )
31
+ if hosts != "" {
32
+ return uninstallK3sFromHosts (user , sshKey , hosts )
32
33
}
33
34
return uninstallK3s (user , sshKey , ip )
34
35
},
@@ -37,7 +38,7 @@ func MakeReset() *cobra.Command {
37
38
cmd .Flags ().StringVarP (& user , "user" , "u" , "" , "Username for SSH connection" )
38
39
cmd .Flags ().StringVarP (& ip , "ip" , "i" , "" , "IP address of the host" )
39
40
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" )
41
42
42
43
return cmd
43
44
}
65
66
return nil
66
67
}
67
68
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 )
70
71
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 )
72
73
}
73
74
74
75
var nodes []Node
75
76
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 )
77
78
}
78
79
79
80
var successNodes []Node
0 commit comments