Skip to content

Commit f0d2c76

Browse files
authored
Merge pull request #29 from dimitraz/cmd-doc
Fix spacing in new command docs
2 parents 6742df5 + bf7554e commit f0d2c76

File tree

2 files changed

+41
-56
lines changed

2 files changed

+41
-56
lines changed

cmd/mobile/main.go

-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ func main() {
5555
createCmd.AddCommand(serviceConfigCmd.CreateServiceConfigCmd())
5656
createCmd.AddCommand(clientBuilds.CreateClientBuildsCmd())
5757
rootCmd.AddCommand(createCmd)
58-
5958
}
6059
//get
6160
{
@@ -99,7 +98,6 @@ func main() {
9998
}
10099

101100
if err := rootCmd.Execute(); err != nil {
102-
103101
os.Exit(1)
104102
}
105103
}

doc/adding_new_cmd.md

+41-54
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,85 @@
11
# Adding a new CLI command
22

3-
43
The mobile CLI uses the [cobra](https://github.com/spf13/cobra) library to provide a consistent framework for building out the CLI tool.
54

65

76
## Adding a new base command
87
### What is a base command
98
A base command is a command that works with an entirely new resource or that adds a new verb i.e (get, delete)
109
### Changes required to add a new base command
11-
to add a new base command that operates on a new resource type you should add a new file under the ```pkg/cmd``` directory
12-
named ```<resourceName>.go``` with an accompanying test file ```<resourceName>_test.go```
10+
To add a new base command that operates on a new resource type you should add a new file under the ```pkg/cmd``` directory
11+
named ```<resourceName>.go``` with an accompanying test file ```<resourceName>_test.go```.
1312
Once this is done, then you should follow the patterns in the other base commands:
1413

1514
- Create a new type ```<resourceName>Cmd```
1615
- Create new constructor ```New<resourceName>Cmd```
1716
- Dependencies such as the kubernetes clients should be passed to this constructor as their interface types to allow for simpler testing
1817
- The cobra commands should then be returned from methods from this the base type. See below:
1918

20-
```
19+
```go
2120
type MyResourceCMD struct{}
2221

23-
func (mr *MyResourceCMD)ListMyResourceCMD()*cobra.Command{}
24-
22+
func (mr *MyResourceCMD) ListMyResourceCMD() *cobra.Command{}
2523
```
2624

2725
This command should then be wired up in ```main.go``` inside the ```cmd/mobile``` pkg.
2826

29-
If it is being added to an existing verb command then add this command in the same way as the other commands
30-
31-
If it is a new verb command then you will want to create a new block of it and its sub commands
27+
If it is being added to an existing verb command then add this command in the same way as the other commands. If it is a new verb command then you will want to create a new block of it and its sub commands.
3228

3329
Example of adding a new resource command:
3430

35-
```
31+
```go
3632
var (
37-
out = os.Stdout
38-
rootCmd = cmd.NewRootCmd()
39-
clientCmd = cmd.NewClientCmd(mobileClient, out)
40-
bindCmd = cmd.NewIntegrationCmd(scClient, k8Client)
41-
serviceConfigCmd = cmd.NewServiceConfigCommand(k8Client)
42-
clientCfgCmd = cmd.NewClientConfigCmd(k8Client)
43-
clientBuilds = cmd.NewClientBuildsCmd()
44-
svcCmd = cmd.NewServicesCmd(scClient, k8Client, out)
45-
// new command added here
46-
myResource = cmd.NewMyResourceCmd(scClient,k8Client, out)
47-
)
33+
out = os.Stdout
34+
rootCmd = cmd.NewRootCmd()
35+
clientCmd = cmd.NewClientCmd(mobileClient, out)
36+
bindCmd = cmd.NewIntegrationCmd(scClient, k8Client)
37+
serviceConfigCmd = cmd.NewServiceConfigCommand(k8Client)
38+
clientCfgCmd = cmd.NewClientConfigCmd(k8Client)
39+
clientBuilds = cmd.NewClientBuildsCmd()
40+
svcCmd = cmd.NewServicesCmd(scClient, k8Client, out)
41+
// new command added here
42+
myResource = cmd.NewMyResourceCmd(scClient,k8Client, out)
43+
)
4844

45+
// create
46+
{
47+
createCmd := cmd.NewCreateCommand()
48+
createCmd.AddCommand(svcCmd.CreateServiceInstanceCmd())
49+
createCmd.AddCommand(bindCmd.CreateIntegrationCmd())
50+
createCmd.AddCommand(clientCmd.CreateClientCmd())
51+
createCmd.AddCommand(serviceConfigCmd.CreateServiceConfigCmd())
52+
createCmd.AddCommand(clientBuilds.CreateClientBuildsCmd())
53+
// sub command added here
54+
createCmd.AddCommand(myResource.CreateMyResourceCmd())
4955

50-
// create
51-
{
52-
createCmd := cmd.NewCreateCommand()
53-
createCmd.AddCommand(svcCmd.CreateServiceInstanceCmd())
54-
createCmd.AddCommand(bindCmd.CreateIntegrationCmd())
55-
createCmd.AddCommand(clientCmd.CreateClientCmd())
56-
createCmd.AddCommand(serviceConfigCmd.CreateServiceConfigCmd())
57-
createCmd.AddCommand(clientBuilds.CreateClientBuildsCmd())
58-
// sub command added here
59-
createCmd.AddCommand(myResource.CreateMyResourceCmd())
60-
61-
rootCmd.AddCommand(createCmd)
62-
63-
}
64-
56+
rootCmd.AddCommand(createCmd)
57+
}
6558
```
6659

6760

68-
Example of adding a new verb command
61+
Example of adding a new verb command:
6962

7063

71-
```
64+
```go
7265
// twist
73-
{
74-
75-
twistCmd := cmd.NewTwistCmd()
76-
twistCmd.AddCommand(myResource.TwistMyResourceCmd())
77-
78-
//important to add it to the root command
79-
rootCmd.AddCommand(twistCmd)
80-
81-
}
66+
{
67+
twistCmd := cmd.NewTwistCmd()
68+
twistCmd.AddCommand(myResource.TwistMyResourceCmd())
69+
70+
// important to add it to the root command
71+
rootCmd.AddCommand(twistCmd)
72+
}
8273

8374
```
8475

85-
8676
### Adding a new command to an existing resource type
8777

8878
You would do this when adding additional functionality to an existing resource type:
8979

9080
- First add a new method to the resource type under <resourceName.go>
91-
```
9281

82+
```go
9383
func (cbc *ClientBuildsCmd) ListClientBuildsCmd() *cobra.Command {
9484
cmd := &cobra.Command{
9585
Use: "clientbuild",
@@ -100,15 +90,12 @@ func (cbc *ClientBuildsCmd) ListClientBuildsCmd() *cobra.Command {
10090
}
10191
return cmd
10292
}
103-
10493
```
10594

10695
You should also then add the testcase for this command:
10796

108-
```
97+
```go
10998
func TestClientBuildsCmd_ListClientBuildsCmd(t *testing.T) {
11099
...
111-
112100
}
113-
114-
```
101+
```

0 commit comments

Comments
 (0)