https://github.com/elliotxx/argparse
A 200-line command-line parsing library
https://github.com/elliotxx/argparse
Last synced: 6 months ago
JSON representation
A 200-line command-line parsing library
- Host: GitHub
- URL: https://github.com/elliotxx/argparse
- Owner: elliotxx
- License: mit
- Created: 2019-11-29T06:41:34.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-11-30T03:21:32.000Z (almost 6 years ago)
- Last Synced: 2025-02-16T05:41:24.604Z (8 months ago)
- Language: Go
- Size: 6.84 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# argparse
A 200-line command-line parsing libraryblog: [200 行代码实现一个简单的命令行解析库](http://yangyingming.com/article/456/)
## Installation
```
$ go get -u -v github.com/elliotxx/argparse
```## Usage
```
package mainimport (
"fmt"
"github.com/elliotxx/argparse"
)func main() {
isr := argparse.Bool("r", false, "Output text in reverse order")
n := argparse.Int("n", -1, "Output n lines")
ish := argparse.Bool("h", false, "Help information")
isH := argparse.Bool("help", false, "Help information")
err := argparse.Parse()
if err != nil {
fmt.Println(err)
return
}if *ish || *isH {
argparse.Help()
return
}
fmt.Printf("isr=%v, n=%d\n", *isr, *n)
}
```
Ouput:
```
$ go run cat.go -h
Usage of cat
-h,--help bool Help information
-n int Output n lines
-r bool Output text in reverse order
```
```
$ go run cat.go -nr 10
isr=true, n=10
```