https://github.com/minghsu0107/go-cli-example
A Go CLI example that shows a simple way to create CLI program with clean project structure.
https://github.com/minghsu0107/go-cli-example
cli docker go
Last synced: 3 months ago
JSON representation
A Go CLI example that shows a simple way to create CLI program with clean project structure.
- Host: GitHub
- URL: https://github.com/minghsu0107/go-cli-example
- Owner: minghsu0107
- Created: 2021-06-06T16:35:13.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2022-01-18T09:42:01.000Z (over 4 years ago)
- Last Synced: 2025-07-03T02:05:32.824Z (about 1 year ago)
- Topics: cli, docker, go
- Language: Go
- Homepage:
- Size: 19.5 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Go CLI Example
A Go CLI example that shows a simple way to create CLI program with clean project structure.
## Installation
Use Docker image:
```bash
docker pull minghsu0107/gce
```
Or you could build from source:
```bash
git clone https://github.com/minghsu0107/go-cli-example.git
cd go-cli-example
go build -o gce
```
## Getting Started
We have two services, `task` and `template`. Each service is a subcommand with its own set of actions and flags. Take `task` service as an example. There are two actions for `task` service, `add` and `complete`, in which `add` adds a new task and `complete` completes the task. To add a task named `mytask` with a weight of 3, for example, you could run:
```bash
./gce task add --name=mytask --weight=3
```
To add additional tags, you could run:
```bash
./gce task add --name=mytask --weight=3 --tags=go,cli,example
# or
./gce task add --name=mytask --weight=3 --tags=go --tags=cli --tags=example
```
You could also pass arguments using environment variables:
```bash
TASK_NAME=mytask TASK_WEIGHT=3 TASK_TAGS=go,cli,example ./gce task add
```
Passing environment variables to Docker container:
```bash
docker run -e TASK_NAME=mytask -e TASK_WEIGHT=3 -e TASK_TAGS=go,cli,example minghsu0107/gce task add
```
Run `./gce --help` to see helps and full options.
Below is an overall project structure to see how commands are organized:
```
go-cli-example/
├── cmd
│ ├── task
│ │ ├── add.go
│ │ ├── complete.go
│ │ └── main.go
│ └── template
│ ├── add.go
│ ├── main.go
│ └── remove.go
├── go.mod
├── go.sum
├── main.go
└── service
├── task
│ ├── add.go
│ ├── complete.go
│ └── config.go
└── template
├── add.go
├── config.go
└── remove.go
```