https://github.com/guillaumefalourd/poc-cli-golang
POC of a CLI project using Golang 🐿 with Cobra.
https://github.com/guillaumefalourd/poc-cli-golang
cli cobra golang poc
Last synced: about 2 months ago
JSON representation
POC of a CLI project using Golang 🐿 with Cobra.
- Host: GitHub
- URL: https://github.com/guillaumefalourd/poc-cli-golang
- Owner: GuillaumeFalourd
- License: apache-2.0
- Created: 2021-08-04T17:35:29.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-02-23T11:30:36.000Z (over 2 years ago)
- Last Synced: 2025-01-12T06:07:12.780Z (9 months ago)
- Topics: cli, cobra, golang, poc
- Language: Go
- Homepage: https://towardsdatascience.com/how-to-create-a-cli-in-golang-with-cobra-d729641c7177
- Size: 61.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# poc-cli-golang
POC of a CLI project using Golang inspired from [this article](https://towardsdatascience.com/how-to-create-a-cli-in-golang-with-cobra-d729641c7177).
## 📑 Requirements
- Golang installed (go1.15 or newer)
- Cobra library (`go get -u github.com/spf13/cobra/cobra`)
- Any code editor of your choice## ⚙️ Setup & Update
At the repository `root` run:
```bash
go install my-cli
```Then, the `my-cli` command should be recognized on your terminal.
_**Note**: If `my-cli` is not recognized by the terminal, please run:_
```bash
export PATH=$PATH:$(go env GOPATH)/bin
```_...or check your `$HOME/go/bin directory` if the `my-cli` bin is there)._
## 🚀 Run
### Login
Will return SUCCESS if `username` and `password` flags are the same.
```bash
my-cli login -u="username" -p = "password"
```### Add
Will return the sum of all numbers used as arguments.
```bash
my-cli add 1 2 3 4
```#### Add Even (Add sub-command)
Will return the sum of all even numbers used as arguments.
```bash
my-cli add even 1 2 3 4
```#### Add Odd (Add sub-command)
Will return the sum of all odd numbers used as arguments.
```bash
my-cli add odd 1 2 3 4
```### Create
Will create something with the specified **arg** `` using the **flag** `--env-from`:
```bash
my-cli create --env-from="dev"
```