Skip to content
This repository was archived by the owner on Nov 5, 2021. It is now read-only.

Commit 5297d60

Browse files
committed
Move to cobra for CLI parsing. jaas is now jaas run
Signed-off-by: Alex Ellis <[email protected]>
1 parent 169b895 commit 5297d60

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+7767
-277
lines changed

CONTRIBUTING.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ This is the contribution process for this repo.
1212
* Please link to the bug and explain how you tested the change
1313
* I'll merge after reviewing/testing
1414

15+
> Note: Dependencies are vendored with [vndr](https://github.com/LK4D4/vndr/blob/master/README.md)
16+
1517
### License
1618

1719
This project is licensed under the MIT License.
@@ -21,7 +23,7 @@ This project is licensed under the MIT License.
2123
Please add a Copyright notice to new files you add where this is not already present:
2224

2325
```
24-
// Copyright (c) OpenFaaS Project 2017. All rights reserved.
26+
// Copyright (c) Alex Ellis 2017-2018. All rights reserved.
2527
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
2628
```
2729

Dockerfile

+5-6
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ FROM golang:1.9.2 as build
22

33
44

5-
RUN mkdir -p /go/src/github.com/alexellis2/jaas
6-
WORKDIR /go/src/github.com/alexellis2/jaas
5+
RUN mkdir -p /go/src/github.com/alexellis/jaas
6+
WORKDIR /go/src/github.com/alexellis/jaas
77

8-
COPY app.go .
9-
COPY show_tasks.go .
10-
COPY poll.go .
11-
COPY vendor vendor
8+
COPY vendor vendor
9+
COPY cmd cmd
10+
COPY main.go .
1211

1312
RUN CGO_ENABLED=0 GOOS=linux go build -a -ldflags "-s -w" -installsuffix cgo -o /root/jaas
1413

README.md

+10-9
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ Now test `jaas` with `jaas --help`
4646

4747
### Running a task / batch job / one-shot container
4848

49-
* Run your first one-shot container:
49+
* Run your first one-shot container with `jaas run`:
5050

5151
```
52-
# jaas -rm -image alexellis2/cows:latest
52+
# jaas run -r --image alexellis2/cows:latest
5353
```
5454

5555
The `-rm` flag removes the Swarm service that was used to run your container.
@@ -58,18 +58,18 @@ The `-rm` flag removes the Swarm service that was used to run your container.
5858
5959
* Hiding logs
6060

61-
If you aren't interested in the output logs then run it with the `--showlogs=false` override:
61+
If you aren't interested in the output logs then run it with the `--show-logs=false` override:
6262

6363
```
64-
# jaas -image alexellis2/cows:latest --showlogs=false
64+
# jaas run --image alexellis2/cows:latest --show-logs=false
6565
```
6666

6767
* Removing service after completion
6868

69-
To remove the service after it completes, run with the `-rm` flag:
69+
To remove the service after it completes, run with the `--remove` or `-r` flag:
7070

7171
```
72-
# jaas -image alexellis2/href-counter:latest --env url=http://blog.alexellis.io/ --showlogs=true
72+
# jaas run --image alexellis2/href-counter:latest --env url=http://blog.alexellis.io/
7373
7474
Service created: peaceful_shirley (uva6bcqyubm1b4c80dghjhb44)
7575
ID: uva6bcqyubm1b4c80dghjhb44 Update at: 2017-03-14 22:19:54.381973142 +0000 UTC
@@ -78,7 +78,6 @@ ID: uva6bcqyubm1b4c80dghjhb44 Update at: 2017-03-14 22:19:54.381973142 +0000
7878
Exit code: 0
7979
State: complete
8080
81-
8281
Printing service logs
8382
?2017-03-14T22:19:55.660902727Z com.docker.swarm.node.id=b2dqydhfavwezorhkqi11f962,com.docker.swarm.service.id=uva6bcqyubm1b4c80dghjhb44,com.docker.swarm.task.id=yruxuawdipz2v5n0wvvm8ib0r {"internal":42,"external":2}
8483
@@ -115,7 +114,7 @@ You can also run `jaas` in a container, but the syntax becomes slightly more ver
115114

116115
```
117116
# docker run -ti -v /var/run/docker.sock:/var/run/docker.sock \
118-
alexellis2/jaas -image alexellis2/cows:latest
117+
alexellis2/jaas run --image alexellis2/cows:latest
119118
```
120119

121120
### Roadmap:
@@ -125,10 +124,12 @@ Here are several features / enhancements on the roadmap, please make additional
125124
* [x] Optionally delete service after fetching exit code/logs
126125
* [x] Support passing environmental variables
127126
* [x] Support private registry auth via `-registryAuth` flag
127+
* [x] Move to cobra flags/args package for CLI
128+
* [x] Support constraints on where to run tasks
128129

129130
Todo:
130131

131-
* [ ] Support constraints on where to run tasks
132+
* [ ] Move vendoring tool to `dep`
132133
* [ ] Support optional secrets through CLI flag
133134
* [ ] Validation around images which are not in local library
134135
* [ ] Extract stdout/stderr etc from logs in human readable format similar to `docker logs`

README_RPI.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This tool will work on the Raspberry Pi / an ARM v6/7 - either running with Go d
88
Running:
99

1010
```
11-
$ docker run -ti -v /var/run/docker.sock:/var/run/docker.sock alexellis2/jaas-armhf ./jaas --showlogs=false -env url=http://www.alexellis.io -image=alexellis2/href-counter-armhf
11+
$ docker run -ti -v /var/run/docker.sock:/var/run/docker.sock alexellis2/jaas-armhf ./jaas run --showlogs=false --env url=http://www.alexellis.io --image=alexellis2/href-counter-armhf
1212
```
1313

1414
Building:

app.go

-137
This file was deleted.

cmd/jaas.go

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (c) Alex Ellis 2017-2018. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
package cmd
5+
6+
import (
7+
"fmt"
8+
"os"
9+
"strings"
10+
11+
"github.com/spf13/cobra"
12+
)
13+
14+
// Execute run the root cobra command
15+
func Execute() {
16+
if err := rootCmd.Execute(); err != nil {
17+
e := err.Error()
18+
fmt.Println(strings.ToUpper(e[:1]) + e[1:])
19+
os.Exit(1)
20+
}
21+
}
22+
23+
var rootCmd = &cobra.Command{
24+
Use: "jaas",
25+
Short: "Run an ad-hoc command",
26+
Long: `
27+
Run ad-hoc commands`,
28+
RunE: executeRoot,
29+
}
30+
31+
func executeRoot(cmd *cobra.Command, args []string) error {
32+
fmt.Printf("JaaS!")
33+
cmd.Help()
34+
35+
return nil
36+
}
37+
38+
func init() {
39+
40+
}

0 commit comments

Comments
 (0)