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