https://github.com/owlinux1000/clib
clib is yet another golang command line parser.
https://github.com/owlinux1000/clib
cli golang library
Last synced: 9 months ago
JSON representation
clib is yet another golang command line parser.
- Host: GitHub
- URL: https://github.com/owlinux1000/clib
- Owner: owlinux1000
- License: mit
- Created: 2018-08-06T10:20:19.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-08-22T12:56:47.000Z (almost 8 years ago)
- Last Synced: 2025-07-28T09:47:09.435Z (10 months ago)
- Topics: cli, golang, library
- Language: Go
- Homepage:
- Size: 36.1 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# clib
[](https://travis-ci.org/owlinux1000/clib)
[](https://godoc.org/github.com/owlinux1000/clib)
[](LICENSE.txt)
clib is yet another golang command line parser.
## Install
```
$ go get github.com/owlinux1000/clib
```
## Example
Here is a sample implemented like ```git add -u``` .
```go
package main
import (
"os"
"fmt"
"github.com/owlinux1000/clib"
)
func main() {
app, err := clib.NewApp("mygit", "1.0.0", "A toy git client")
if err != nil {
panic(err)
}
if err := app.AddCommand("add", "a", "Add file contents to the index", 0); err != nil {
panic(err)
}
if err := app.AddOption("-u", "update tracked files", 0); err != nil {
panic(err)
}
exitStatus, err := app.Parse(os.Args)
if err != nil {
panic(err)
}
if ok, _ := app.OptionFlag("-h"); ok {
fmt.Println(app.Usage())
os.Exit(exitStatus)
}
if ok, _ := app.CommandFlag("add"); ok {
fmt.Println("You executed `mygit add`")
if ok, _ := app.OptionFlag("-u"); ok {
fmt.Println("You executed `mygit add -u`")
}
}
}
```
The result executed `go run` is here.
```
$ mygit
A toy git client
Usage:
mygit [option]
mygit
Options:
-h Display this message
-u update tracked files
-v Print version info and exit
Commands:
add Add file contents to the index
```