Skip to content

Commit dd24cb4

Browse files
committed
Add initial code
1 parent e9395d3 commit dd24cb4

30 files changed

+1420
-0
lines changed

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.DS_Store
2+
bin
3+
dist
4+
tmp
5+
vendor
6+
.envrc

.goimportsignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.vscode
2+
.DS_Store
3+
bin
4+
dist
5+
tmp

.golangci.yml

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Refer to https://golangci-lint.run/usage/configuration/
2+
3+
run:
4+
concurrency: 4
5+
timeout: 5m
6+
skip-dirs:
7+
- .git
8+
- .vscode
9+
- scripts
10+
- tmp
11+
- dist
12+
- vendor
13+
modules-download-mode: readonly
14+
allow-parallel-runners: true
15+
16+
output:
17+
sort-results: true
18+
19+
linters:
20+
disable-all: true
21+
enable:
22+
- bodyclose
23+
- deadcode
24+
- depguard
25+
- dogsled
26+
- errcheck
27+
- exhaustive
28+
- exportloopref
29+
- funlen
30+
- gochecknoinits
31+
- goconst
32+
- gocritic
33+
- gocyclo
34+
- gofmt
35+
- goimports
36+
- golint
37+
- gomnd
38+
- goprintffuncname
39+
- gosec
40+
- gosimple
41+
- govet
42+
- ineffassign
43+
- lll
44+
- nakedret
45+
- noctx
46+
- nolintlint
47+
- rowserrcheck
48+
- staticcheck
49+
- structcheck
50+
- typecheck
51+
- unconvert
52+
- unparam
53+
- unused
54+
- varcheck
55+
- whitespace
56+
57+
# linters-settings inspired by prometheus/prometheus.
58+
linters-settings:
59+
depguard:
60+
list-type: blacklist
61+
include-go-root: true
62+
packages:
63+
- sync/atomic
64+
- github.com/stretchr/testify/assert
65+
funlen:
66+
lines: 100
67+
statements: 50
68+
lll:
69+
line-length: 150
70+
71+
# issues was inspired by uber-go/guide.
72+
issues:
73+
exclude-use-default: false
74+
max-issues-per-linter: 0
75+
max-same-issues: 0
76+
# issues.exclude-rules was inspired by prometheus/prometheus.
77+
exclude-rules:
78+
- path: _test.go
79+
linters:
80+
- errcheck

.goreleaser.yml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# .goreleaser.yml
2+
3+
project_name: atmos-cli
4+
5+
env:
6+
- GO111MODULE=on
7+
8+
# Build destination
9+
github_urls:
10+
# set to true if you use a self-signed certificate
11+
skip_tls_verify: false
12+
13+
before:
14+
hooks:
15+
- go mod tidy
16+
17+
builds:
18+
- main: cmd/main.go
19+
id: atmos-cli
20+
binary: atmos
21+
targets:
22+
- linux_amd64
23+
- linux_arm64
24+
- darwin_amd64
25+
- darwin_arm64
26+
- windows_amd64
27+
ldflags:
28+
- -s -w
29+
env:
30+
- CGO_ENABLED=0
31+
asmflags:
32+
- all=-trimpath={{.Env.GOPATH}}
33+
gcflags:
34+
- all=-trimpath={{.Env.GOPATH}}
35+
36+
archives:
37+
- name_template: '{{ .ProjectName }}-v{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
38+
39+
release:
40+
prerelease: auto
41+
42+
checksum:
43+
name_template: "{{ .ProjectName }}-v{{ .Version }}_checksums.txt"

.husky.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
hooks:
2+
pre-commit:
3+
- golangci-lint run
4+
- husky lint-staged
5+
6+
lint-staged:
7+
"*.go":
8+
- gofmt -l -w

.markdownlint.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"default": true,
3+
"line_length": false,
4+
"no-inline-html": false,
5+
"no-trailing-punctuation": false,
6+
"no-duplicate-heading": false,
7+
"no-bare-urls": false,
8+
"header-increment": false,
9+
"no-alt-text": false
10+
}

.markdownlintignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
bin
2+
cli
3+
cmd
4+
internal
5+
pkg
6+
dist
7+
tmp

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 umatare5
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Makefile
2+
3+
.PHONY: build
4+
build:
5+
goreleaser release --snapshot --rm-dist
6+
7+
.PHONY: test
8+
test:
9+
go test -v -race ./cmd/main.go
10+
11+
.PHONY: release
12+
release:
13+
git bump
14+
goreleaser release --rm-dist

README.md

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# atmos-cli
2+
3+
atmos-cli is a CLI to fetch divelogs from ATMOS Platform.
4+
5+
![](https://github.com/umatare5/atmos-cli/blob/images/promo.gif)
6+
7+
## Syntax
8+
9+
```bash
10+
$ atmos
11+
NAME:
12+
atmos - Client for ATMOS Platform
13+
14+
USAGE:
15+
atmos COMMAND [options...]
16+
17+
VERSION:
18+
0.1.0
19+
20+
COMMANDS:
21+
profile, p, pr, pro, prof Fetch my profile.
22+
divelog, d, di, div, dive Fetch my divelogs.
23+
help, h Shows a list of commands or help for one command
24+
25+
GLOBAL OPTIONS:
26+
--server value, -s value URI to ATMOS API (default: "https://localhost/") [$ATMOS_API]
27+
--help, -h show help (default: false)
28+
--version, -v print the version (default: false)
29+
```
30+
31+
- Environment Variables
32+
33+
| Environment Varible | Alternative to | Description |
34+
| ------------------- | ------------------- | ------------------------------------ |
35+
| ATMOS_API | --server (-s) | URI of ATMOS Platform API. |
36+
| ATMOS_USERID | --user-id (-i) | Unique ID in ATMOS Platform. |
37+
| ATMOS_TOKEN | --access-token (-t) | The token to use ATMOS Platform API. |
38+
39+
## Usage
40+
41+
### Tutorial
42+
43+
- Show the latest 10 dive-logs in pretty format.
44+
45+
```bash
46+
atmos divelog --pretty
47+
```
48+
49+
- Show the latest 5 dive-logs in pretty format.
50+
51+
```bash
52+
atmos divelog --pretty --limit 5
53+
```
54+
55+
- Show the cursor at end of latest 10 dive-logs.
56+
57+
```bash
58+
atmos divelog | jq -r '.response.page_info.end_cursor'
59+
```
60+
61+
- Show 10 dive-logs after selected cursor in pretty format.
62+
63+
```bash
64+
atmos divelog --pretty --cursor $END_CURSOR_NAME
65+
```
66+
67+
## Advanced
68+
69+
- `atmos divelog --divelog-id` shows the detail of a divelog.
70+
71+
```bash
72+
atmos divelog --divelog-id <randomChar> | jq .
73+
```
74+
75+
```bash
76+
{
77+
"code": "0000000",
78+
"message": "",
79+
"response": {
80+
"divelog": {
81+
"air_in": 0,
82+
"air_in_text": "0",
83+
"air_out": 0,
84+
"air_out_text": "0",
85+
"air_temperature": "27.1",
86+
<snip>
87+
}
88+
}
89+
}
90+
```
91+
92+
- `atmos profile` shows user profile.
93+
94+
```bash
95+
atmos profile | jq .
96+
```
97+
98+
```bash
99+
{
100+
"code": "0000000",
101+
"message": "",
102+
"response": {
103+
"user": {
104+
"user_name": "umatare5",
105+
"status": "active",
106+
<snip>
107+
}
108+
}
109+
}
110+
```
111+
112+
- `atmos profile --statistics` shows user statistics.
113+
114+
```bash
115+
atmos divelog --statistics | jq .
116+
```
117+
118+
```bash
119+
{
120+
"code": "0000000",
121+
"message": "",
122+
"response": {
123+
"dive_time": 140437,
124+
"divelog_count": 42,
125+
"follower_count": 0,
126+
"following_count": 0,
127+
<snip>
128+
}
129+
}
130+
```

cli/command/divelog.go

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package command
2+
3+
import (
4+
"github.com/umatare5/atmos-cli/internal/application"
5+
"github.com/umatare5/atmos-cli/internal/config"
6+
"github.com/umatare5/atmos-cli/internal/domain"
7+
"github.com/umatare5/atmos-cli/internal/framework"
8+
"github.com/umatare5/atmos-cli/internal/infrastructure"
9+
10+
"github.com/urfave/cli/v2"
11+
)
12+
13+
// registerDivelogFlags returns command flags
14+
func registerDivelogFlags() []cli.Flag {
15+
flags := []cli.Flag{}
16+
flags = append(flags, registerAccessTokenFlag()...)
17+
flags = append(flags, registerDivelogIDFlag()...)
18+
flags = append(flags, registerLimitFlag()...)
19+
flags = append(flags, registerCursorFlag()...)
20+
flags = append(flags, registerPrettyFormatFlag()...)
21+
return flags
22+
}
23+
24+
// registerDivelogCommand executes the command
25+
func registerDivelogCommand() []*cli.Command {
26+
return []*cli.Command{
27+
{
28+
Name: domain.DivelogCommandName,
29+
Usage: domain.DivelogCommandUsage,
30+
Aliases: domain.DivelogCommandAlias,
31+
Flags: registerDivelogFlags(),
32+
Action: func(ctx *cli.Context) error {
33+
c := config.New(ctx)
34+
r := infrastructure.New(&c)
35+
u := application.New(&c, &r)
36+
exec := framework.New(&c, &r, &u)
37+
38+
if ctx.String(domain.DivelogIDFlagName) != domain.DivelogIDFlagDefaultValue {
39+
exec.GetDivelog(
40+
ctx.String(domain.DivelogIDFlagName),
41+
ctx.Bool(domain.PrettyFormatFlagName),
42+
)
43+
return nil
44+
}
45+
if ctx.Bool(domain.PrettyFormatFlagName) {
46+
exec.GetDivelogsPretty()
47+
return nil
48+
}
49+
50+
exec.GetDivelogs()
51+
return nil
52+
},
53+
},
54+
}
55+
}

0 commit comments

Comments
 (0)