Skip to content

Commit 7e41a4c

Browse files
authored
Merge pull request #25 from maleck13/1859-dev-docs
1859 dev docs for contributing and add a new command
2 parents 44606c7 + 153c28c commit 7e41a4c

5 files changed

+215
-2
lines changed

.github/ISSUE_TEMPLATE.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
**This form is for bug reports and feature requests. Major features will go through a [proposal process](https://github.com/aerogear/mobile-cli/blob/master/CONTRIBUTING.adoc).**
2+
3+
> # Feature:
4+
> # Bug:
5+
6+
**What happened**:
7+
8+
**What you expected to happen**:
9+
10+
**How to reproduce it**:

.github/PULL_REQUEST_TEMPLATE.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
**Describe what this PR does and why we need it**:
2+
3+
Changes proposed in this pull request
4+
-
5+
-
6+
-
7+
8+
**Does this PR depend on another PR (Use this to track when PRs should be merged)**
9+
depends-on <PR>
10+
11+
**Which issue this PR fixes (This will close that issue when PR gets merged)**
12+
fixes <issue_number>

CONTRIBUTING.adoc

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
= Contributing to the mobile CLI
2+
3+
This document explains how to set up a development environment and get involved with Mobile CLI project.
4+
5+
Before anything else, https://help.github.com/articles/fork-a-repo/[fork] the Mobile CLI project.
6+
7+
== Tools We use
8+
9+
* Git
10+
* Go
11+
* Make
12+
13+
== Set Up OpenShift
14+
15+
The Mobile CLI targets Kubernetes and is intended to be developed against a running Kubernetes cluster,
16+
we use OpenShift as our Kubernetes distribution. The Mobile CLI is intended to help you work with Mobile Services running ontop of OpenShift.
17+
To provision these services, we levarage the https://github.com/kubernetes-incubator/service-catalog[Service Catalog] and the https://github.com/openshift/ansible-service-broker[Ansible Service Broker].
18+
To help get this infrastructure set up there is a https://github.com/aerogear/mobile-core#installing-from-a-development-release[ansible based installer] provided.
19+
20+
== Clone the repositiory
21+
22+
As we are using Go, the path you clone this repo into is important.
23+
24+
* create the directory `mkdir -p $GOPATH/src/github.com/aerogear`
25+
* clone the repo `cd $GOPATH/src/github.com/aerogear &amp;&amp; git clone git@github.com:aerogear/mobile-CLI.git`
26+
* add your own fork as the upstream target `git add remote upstream &lt;your fork&gt;`
27+
28+
== Building the Mobile CLI
29+
30+
To build the CLI locally you can run `make build` this command will run a set of checks and the unit tests before compiling the binary and outputting it into the current directory,
31+
if you only want to build the binary itself you can simply run `make build_binary`.
32+
Once built, you can access this binary and use it from the command line `./mobile`
33+
Remember however that the CLI is intended as a Kubernetes plugin so expects to find kube configuration in `~/.kube/config`. If you have setup OpenShift this should
34+
already be in place.
35+
36+
== Submitting changes to the Mobile CLI
37+
38+
=== Before making a pull request
39+
40+
There are a few things you should keep in mind before creating a PR.
41+
42+
* New code should have corresponding unit tests. An example of how we approach unit testing can be found in https://github.com/aerogear/mobile-CLI/blob/master/pkg/cmd/clients_test.go[clients_test.go].
43+
44+
* Ensure for new commands to read the https://github.com/aerogear/mobile-CLI/doc/adding_new_cmd.md[adding a new command] doc before hand.
45+
46+
* You Must run ```make build``` before creating the PR and ensure it must execute with no errors.
47+
48+
* When needed provide an explanation of the command and the expected output to help others that may review and test the change.
49+
50+
=== Making a pull request
51+
52+
Make a https://help.github.com/articles/using-pull-requests[pull request (PR)] in the standard way.
53+
54+
Use [WIP] at the beginning of the title (ie. [WIP] Add feature to the CLI) to mark a PR as a Work in Progress.
55+
56+
Your PR will then be reviewed, questions may be asked and changes requested.
57+
58+
Upon successful review, someone will approve the PR in the review thread. Depending on the size of the change, we may wait for 2 LGTM from reviewers before merging.
59+
60+
61+
=== Major features
62+
63+
The aerogear community uses a proposal process when introducing a major feature in order to encourage collaboration and building the best solution.
64+
65+
Major features are things that take about 2 weeks of development or introduce disruptive changes to the code base.
66+
67+
Start the proposal process by reviewing the https://github.com/aerogear/proposals/blob/master/template.md[proposal template]. Use this document to guide how to write a proposal. Then, submit it as a pull request where the community will review the plan.
68+
69+
The proposal process also requires two approvals from the community before merging.
70+
71+
== Stay in touch
72+
73+
* IRC: Join the conversation on Freenode: #aerogear
74+
* Email: Subscribe to the https://github.com/aerogear/mobile-CLI/doc/adding_new_cmd.md[aerogear mailing list]

Makefile

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@ LDFLAGS=-ldflags "-w -s -X main.Version=${TAG}"
1010
setup:
1111
@go get github.com/kisielk/errcheck
1212

13-
build: setup check
13+
build: setup check build_binary
1414
go build -o mobile ./cmd/mobile
1515

16-
build_linux:
16+
build_binary_linux:
1717
env GOOS=linux GOARCH=amd64 go build -o mobile ./cmd/mobile
1818

19+
build_binary:
20+
go build -o mobile ./cmd/mobile
21+
1922
generate:
2023
./scripts/generate.sh
2124

doc/adding_new_cmd.md

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# Adding a new CLI command
2+
3+
4+
The mobile CLI uses the [cobra](https://github.com/spf13/cobra) library to provide a consistent framework for building out the CLI tool.
5+
6+
7+
## Adding a new base command
8+
### What is a base command
9+
A base command is a command that works with an entirely new resource or that adds a new verb i.e (get, delete)
10+
### 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```
13+
Once this is done, then you should follow the patterns in the other base commands:
14+
15+
- Create a new type ```<resourceName>Cmd```
16+
- Create new constructor ```New<resourceName>Cmd```
17+
- Dependencies such as the kubernetes clients should be passed to this constructor as their interface types to allow for simpler testing
18+
- The cobra commands should then be returned from methods from this the base type. See below:
19+
20+
```
21+
type MyResourceCMD struct{}
22+
23+
func (mr *MyResourceCMD)ListMyResourceCMD()*cobra.Command{}
24+
25+
```
26+
27+
This command should then be wired up in ```main.go``` inside the ```cmd/mobile``` pkg.
28+
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
32+
33+
Example of adding a new resource command:
34+
35+
```
36+
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+
)
48+
49+
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+
65+
```
66+
67+
68+
Example of adding a new verb command
69+
70+
71+
```
72+
// 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+
}
82+
83+
```
84+
85+
86+
### Adding a new command to an existing resource type
87+
88+
You would do this when adding additional functionality to an existing resource type:
89+
90+
- First add a new method to the resource type under <resourceName.go>
91+
```
92+
93+
func (cbc *ClientBuildsCmd) ListClientBuildsCmd() *cobra.Command {
94+
cmd := &cobra.Command{
95+
Use: "clientbuild",
96+
Short: "get a specific clientbuild for a mobile client",
97+
RunE: func(cmd *cobra.Command, args []string) error {
98+
...
99+
},
100+
}
101+
return cmd
102+
}
103+
104+
```
105+
106+
You should also then add the testcase for this command:
107+
108+
```
109+
func TestClientBuildsCmd_ListClientBuildsCmd(t *testing.T) {
110+
...
111+
112+
}
113+
114+
```

0 commit comments

Comments
 (0)