1
1
package cmd
2
2
3
3
import (
4
+ "cdr.dev/coder-cli/internal/x/xcobra"
4
5
"fmt"
5
6
6
7
"github.com/spf13/cobra"
@@ -29,17 +30,17 @@ func providersCmd() *cobra.Command {
29
30
30
31
func createProviderCmd () * cobra.Command {
31
32
var (
32
- name string
33
33
hostname string
34
34
clusterAddress string
35
35
)
36
36
cmd := & cobra.Command {
37
- Use : "create --name=[name] --hostname=[hostname] --clusterAddress=[clusterAddress]" ,
37
+ Use : "create [name] --hostname=[hostname] --clusterAddress=[clusterAddress]" ,
38
+ Args : xcobra .ExactArgs (1 ),
38
39
Short : "create a new workspace provider." ,
39
40
Long : "Create a new Coder workspace provider." ,
40
41
Example : `# create a new workspace provider in a pending state
41
42
42
- coder providers create --name= my-provider --hostname=provider.example.com --clusterAddress= 255.255.255.255` ,
43
+ coder providers create my-provider --hostname=https:// provider.example.com --cluster-address=https:// 255.255.255.255` ,
43
44
RunE : func (cmd * cobra.Command , args []string ) error {
44
45
ctx := cmd .Context ()
45
46
@@ -48,8 +49,9 @@ coder providers create --name=my-provider --hostname=provider.example.com --clus
48
49
return err
49
50
}
50
51
52
+ // ExactArgs(1) ensures our name value can't panic on an out of bounds.
51
53
createReq := & coder.CreateWorkspaceProviderReq {
52
- Name : name ,
54
+ Name : args [ 0 ] ,
53
55
Type : coder .WorkspaceProviderKubernetes ,
54
56
Hostname : hostname ,
55
57
ClusterAddress : clusterAddress ,
@@ -70,12 +72,10 @@ coder providers create --name=my-provider --hostname=provider.example.com --clus
70
72
},
71
73
}
72
74
73
- cmd .Flags ().StringVar (& name , "name" , "" , "workspace provider name" )
74
75
cmd .Flags ().StringVar (& hostname , "hostname" , "" , "workspace provider hostname" )
75
- cmd .Flags ().StringVar (& clusterAddress , "clusterAddress" , "" , "kubernetes cluster apiserver endpoint" )
76
- _ = cmd .MarkFlagRequired ("name" )
76
+ cmd .Flags ().StringVar (& clusterAddress , "cluster-address" , "" , "kubernetes cluster apiserver endpoint" )
77
77
_ = cmd .MarkFlagRequired ("hostname" )
78
- _ = cmd .MarkFlagRequired ("clusterAdress " )
78
+ _ = cmd .MarkFlagRequired ("cluster-address " )
79
79
return cmd
80
80
}
81
81
0 commit comments