Skip to content

Commit 94c12a8

Browse files
authored
Merge pull request #51 from serverscom/k8s-list-nodes-error
add cluster-id arg validation
2 parents ec87008 + c987555 commit 94c12a8

9 files changed

Lines changed: 74 additions & 70 deletions

File tree

cmd/entities/hosts/connections.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package hosts
22

33
import (
4-
"log"
5-
64
serverscom "github.com/serverscom/serverscom-go-client/pkg"
75
"github.com/serverscom/srvctl/cmd/base"
86
"github.com/spf13/cobra"
@@ -11,14 +9,14 @@ import (
119
func newListDSConnectionsCmd(cmdContext *base.CmdContext) *cobra.Command {
1210
factory := func(verbose bool, args ...string) serverscom.Collection[serverscom.HostConnection] {
1311
scClient := cmdContext.GetClient().SetVerbose(verbose).GetScClient()
14-
if len(args) == 0 {
15-
log.Fatal("Missing dedicated server ID")
16-
}
17-
id := args[0]
18-
return scClient.Hosts.DedicatedServerConnections(id)
12+
return scClient.Hosts.DedicatedServerConnections(args[0])
1913
}
2014

2115
opts := &base.BaseListOptions[serverscom.HostConnection]{}
2216

23-
return base.NewListCmd("list-connections <id>", "Dedicated server connections", factory, cmdContext, opts)
17+
cmd := base.NewListCmd("list-connections", "Dedicated server connections", factory, cmdContext, opts)
18+
cmd.Use = "list-connections <id>"
19+
cmd.Args = cobra.ExactArgs(1)
20+
21+
return cmd
2422
}

cmd/entities/hosts/drive-slots.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package hosts
22

33
import (
4-
"log"
5-
64
serverscom "github.com/serverscom/serverscom-go-client/pkg"
75
"github.com/serverscom/srvctl/cmd/base"
86
"github.com/spf13/cobra"
@@ -11,32 +9,32 @@ import (
119
func newListDSDriveSlotsCmd(cmdContext *base.CmdContext) *cobra.Command {
1210
factory := func(verbose bool, args ...string) serverscom.Collection[serverscom.HostDriveSlot] {
1311
scClient := cmdContext.GetClient().SetVerbose(verbose).GetScClient()
14-
if len(args) == 0 {
15-
log.Fatal("Missing dedicated server ID")
16-
}
17-
id := args[0]
18-
return scClient.Hosts.DedicatedServerDriveSlots(id)
12+
return scClient.Hosts.DedicatedServerDriveSlots(args[0])
1913
}
2014

2115
opts := &base.BaseListOptions[serverscom.HostDriveSlot]{}
2216

23-
return base.NewListCmd("list-drive-slots <id>", "Dedicated server drive slots", factory, cmdContext, opts)
17+
cmd := base.NewListCmd("list-drive-slots", "Dedicated server drive slots", factory, cmdContext, opts)
18+
cmd.Use = "list-drive-slots <id>"
19+
cmd.Args = cobra.ExactArgs(1)
20+
21+
return cmd
2422
}
2523

2624
func newListKBMDriveSlotsCmd(cmdContext *base.CmdContext) *cobra.Command {
2725
factory := func(verbose bool, args ...string) serverscom.Collection[serverscom.HostDriveSlot] {
2826
scClient := cmdContext.GetClient().SetVerbose(verbose).GetScClient()
29-
if len(args) == 0 {
30-
log.Fatal("Missing KBM node ID")
31-
}
32-
id := args[0]
33-
return scClient.Hosts.KubernetesBaremetalNodeDriveSlots(id)
27+
return scClient.Hosts.KubernetesBaremetalNodeDriveSlots(args[0])
3428
}
3529

3630
opts := base.NewListOptions(
3731
&base.BaseListOptions[serverscom.HostDriveSlot]{},
3832
&base.SearchPatternOption[serverscom.HostDriveSlot]{},
3933
)
4034

41-
return base.NewListCmd("list-drive-slots <id>", "KBM node drive slots", factory, cmdContext, opts...)
35+
cmd := base.NewListCmd("list-drive-slots", "KBM node drive slots", factory, cmdContext, opts...)
36+
cmd.Use = "list-drive-slots <id>"
37+
cmd.Args = cobra.ExactArgs(1)
38+
39+
return cmd
4240
}

cmd/entities/hosts/features.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package hosts
22

33
import (
4-
"log"
5-
64
serverscom "github.com/serverscom/serverscom-go-client/pkg"
75
"github.com/serverscom/srvctl/cmd/base"
86
"github.com/spf13/cobra"
@@ -11,14 +9,14 @@ import (
119
func newListDSFeaturesCmd(cmdContext *base.CmdContext) *cobra.Command {
1210
factory := func(verbose bool, args ...string) serverscom.Collection[serverscom.DedicatedServerFeature] {
1311
scClient := cmdContext.GetClient().SetVerbose(verbose).GetScClient()
14-
if len(args) == 0 {
15-
log.Fatal("Missing dedicated server ID")
16-
}
17-
id := args[0]
18-
return scClient.Hosts.DedicatedServerFeatures(id)
12+
return scClient.Hosts.DedicatedServerFeatures(args[0])
1913
}
2014

2115
opts := &base.BaseListOptions[serverscom.DedicatedServerFeature]{}
2216

23-
return base.NewListCmd("list-features <id>", "Dedicated server features", factory, cmdContext, opts)
17+
cmd := base.NewListCmd("list-features", "Dedicated server features", factory, cmdContext, opts)
18+
cmd.Use = "list-features <id>"
19+
cmd.Args = cobra.ExactArgs(1)
20+
21+
return cmd
2422
}

cmd/entities/hosts/networks.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package hosts
22

33
import (
4-
"log"
5-
64
serverscom "github.com/serverscom/serverscom-go-client/pkg"
75
"github.com/serverscom/srvctl/cmd/base"
86
"github.com/spf13/cobra"
@@ -11,11 +9,7 @@ import (
119
func newListDSNetworksCmd(cmdContext *base.CmdContext) *cobra.Command {
1210
factory := func(verbose bool, args ...string) serverscom.Collection[serverscom.Network] {
1311
scClient := cmdContext.GetClient().SetVerbose(verbose).GetScClient()
14-
if len(args) == 0 {
15-
log.Fatal("Missing dedicated server ID")
16-
}
17-
id := args[0]
18-
return scClient.Hosts.DedicatedServerNetworks(id)
12+
return scClient.Hosts.DedicatedServerNetworks(args[0])
1913
}
2014

2115
opts := base.NewListOptions(
@@ -27,7 +21,11 @@ func newListDSNetworksCmd(cmdContext *base.CmdContext) *cobra.Command {
2721
&base.AdditionalOption[serverscom.Network]{},
2822
)
2923

30-
return base.NewListCmd("list-networks <id>", "Dedicated server networks", factory, cmdContext, opts...)
24+
cmd := base.NewListCmd("list-networks", "Dedicated server networks", factory, cmdContext, opts...)
25+
cmd.Use = "list-networks <id>"
26+
cmd.Args = cobra.ExactArgs(1)
27+
28+
return cmd
3129
}
3230

3331
func newGetDSNetworkCmd(cmdContext *base.CmdContext) *cobra.Command {
@@ -160,11 +158,7 @@ func newDeleteDSNetworkCmd(cmdContext *base.CmdContext) *cobra.Command {
160158
func newListKBMNetworksCmd(cmdContext *base.CmdContext) *cobra.Command {
161159
factory := func(verbose bool, args ...string) serverscom.Collection[serverscom.Network] {
162160
scClient := cmdContext.GetClient().SetVerbose(verbose).GetScClient()
163-
if len(args) == 0 {
164-
log.Fatal("Missing KBM node ID")
165-
}
166-
id := args[0]
167-
return scClient.Hosts.KubernetesBaremetalNodeNetworks(id)
161+
return scClient.Hosts.KubernetesBaremetalNodeNetworks(args[0])
168162
}
169163

170164
opts := base.NewListOptions(
@@ -176,5 +170,9 @@ func newListKBMNetworksCmd(cmdContext *base.CmdContext) *cobra.Command {
176170
&base.AdditionalOption[serverscom.Network]{},
177171
)
178172

179-
return base.NewListCmd("list-networks <id>", "KBM node networks", factory, cmdContext, opts...)
173+
cmd := base.NewListCmd("list-networks", "KBM node networks", factory, cmdContext, opts...)
174+
cmd.Use = "list-networks <id>"
175+
cmd.Args = cobra.ExactArgs(1)
176+
177+
return cmd
180178
}

cmd/entities/hosts/ptr.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package hosts
22

33
import (
4-
"log"
5-
64
serverscom "github.com/serverscom/serverscom-go-client/pkg"
75
"github.com/serverscom/srvctl/cmd/base"
86
"github.com/spf13/cobra"
@@ -11,16 +9,16 @@ import (
119
func newListDSPTRCmd(cmdContext *base.CmdContext) *cobra.Command {
1210
factory := func(verbose bool, args ...string) serverscom.Collection[serverscom.PTRRecord] {
1311
scClient := cmdContext.GetClient().SetVerbose(verbose).GetScClient()
14-
if len(args) == 0 {
15-
log.Fatal("Missing dedicated server ID")
16-
}
17-
id := args[0]
18-
return scClient.Hosts.DedicatedServerPTRRecords(id)
12+
return scClient.Hosts.DedicatedServerPTRRecords(args[0])
1913
}
2014

2115
opts := &base.BaseListOptions[serverscom.PTRRecord]{}
2216

23-
return base.NewListCmd("list-ptr <id>", "Dedicated server PTR records", factory, cmdContext, opts)
17+
cmd := base.NewListCmd("list-ptr", "Dedicated server PTR records", factory, cmdContext, opts)
18+
cmd.Use = "list-ptr <id>"
19+
cmd.Args = cobra.ExactArgs(1)
20+
21+
return cmd
2422
}
2523

2624
func newCreateDSPTRCmd(cmdContext *base.CmdContext) *cobra.Command {
@@ -116,16 +114,16 @@ func newDeleteDSPTRCmd(cmdContext *base.CmdContext) *cobra.Command {
116114
func newListSBMPTRCmd(cmdContext *base.CmdContext) *cobra.Command {
117115
factory := func(verbose bool, args ...string) serverscom.Collection[serverscom.PTRRecord] {
118116
scClient := cmdContext.GetClient().SetVerbose(verbose).GetScClient()
119-
if len(args) == 0 {
120-
log.Fatal("Missing SBM server ID")
121-
}
122-
id := args[0]
123-
return scClient.Hosts.SBMServerPTRRecords(id)
117+
return scClient.Hosts.SBMServerPTRRecords(args[0])
124118
}
125119

126120
opts := &base.BaseListOptions[serverscom.PTRRecord]{}
127121

128-
return base.NewListCmd("list-ptr <id>", "SBM server PTR records", factory, cmdContext, opts)
122+
cmd := base.NewListCmd("list-ptr", "SBM server PTR records", factory, cmdContext, opts)
123+
cmd.Use = "list-ptr <id>"
124+
cmd.Args = cobra.ExactArgs(1)
125+
126+
return cmd
129127
}
130128

131129
func newCreateSBMPTRCmd(cmdContext *base.CmdContext) *cobra.Command {

cmd/entities/hosts/services.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package hosts
22

33
import (
4-
"log"
5-
64
serverscom "github.com/serverscom/serverscom-go-client/pkg"
75
"github.com/serverscom/srvctl/cmd/base"
86
"github.com/spf13/cobra"
@@ -11,14 +9,14 @@ import (
119
func newListDSServicesCmd(cmdContext *base.CmdContext) *cobra.Command {
1210
factory := func(verbose bool, args ...string) serverscom.Collection[serverscom.DedicatedServerService] {
1311
scClient := cmdContext.GetClient().SetVerbose(verbose).GetScClient()
14-
if len(args) == 0 {
15-
log.Fatal("Missing dedicated server ID")
16-
}
17-
id := args[0]
18-
return scClient.Hosts.DedicatedServerServices(id)
12+
return scClient.Hosts.DedicatedServerServices(args[0])
1913
}
2014

2115
opts := &base.BaseListOptions[serverscom.DedicatedServerService]{}
2216

23-
return base.NewListCmd("list-services <id>", "Dedicated server services", factory, cmdContext, opts)
17+
cmd := base.NewListCmd("list-services", "Dedicated server services", factory, cmdContext, opts)
18+
cmd.Use = "list-services <id>"
19+
cmd.Args = cobra.ExactArgs(1)
20+
21+
return cmd
2422
}

cmd/entities/k8s/list.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,9 @@ func newListNodesCmd(cmdContext *base.CmdContext) *cobra.Command {
3434
&base.LabelSelectorOption[serverscom.KubernetesClusterNode]{},
3535
)
3636

37-
return base.NewListCmd("list-nodes <cluster-id>", "kubernetes cluster nodes by ID", factory, cmdContext, opts...)
37+
cmd := base.NewListCmd("list-nodes", "kubernetes cluster nodes", factory, cmdContext, opts...)
38+
cmd.Use = "list-nodes <cluster-id>"
39+
cmd.Args = cobra.ExactArgs(1)
40+
41+
return cmd
3842
}

cmd/entities/l2_segments/list.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ func newListMembersCmd(cmdContext *base.CmdContext) *cobra.Command {
4545
&base.L2SegmentGroupTypeOption[serverscom.L2Member]{},
4646
)
4747

48-
return base.NewListCmd("list-members", "l2 segment members", factory, cmdContext, opts...)
48+
cmd := base.NewListCmd("list-members", "l2 segment members", factory, cmdContext, opts...)
49+
cmd.Use = "list-members <l2-segment-id>"
50+
cmd.Args = cobra.ExactArgs(1)
51+
52+
return cmd
4953
}
5054

5155
func newListNetworksCmd(cmdContext *base.CmdContext) *cobra.Command {
@@ -60,5 +64,9 @@ func newListNetworksCmd(cmdContext *base.CmdContext) *cobra.Command {
6064
&base.L2SegmentGroupTypeOption[serverscom.Network]{},
6165
)
6266

63-
return base.NewListCmd("list-networks", "l2 segment networks", factory, cmdContext, opts...)
67+
cmd := base.NewListCmd("list-networks", "l2 segment networks", factory, cmdContext, opts...)
68+
cmd.Use = "list-networks <l2-segment-id>"
69+
cmd.Args = cobra.ExactArgs(1)
70+
71+
return cmd
6472
}

cmd/entities/network-pools/list.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,9 @@ func newListSubnetsCmd(cmdContext *base.CmdContext) *cobra.Command {
3535
&base.AttachedSubnetworksOption[serverscom.Subnetwork]{},
3636
)
3737

38-
return base.NewListCmd("list-subnets", "subnets for a network pool", factory, cmdContext, opts...)
38+
cmd := base.NewListCmd("list-subnets", "subnets for a network pool", factory, cmdContext, opts...)
39+
cmd.Use = "list-subnets <network-pool-id>"
40+
cmd.Args = cobra.ExactArgs(1)
41+
42+
return cmd
3943
}

0 commit comments

Comments
 (0)