Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/posener/flag
Like the flag package, but with bash completion support!
https://github.com/posener/flag
bash-completion flag go
Last synced: 19 days ago
JSON representation
Like the flag package, but with bash completion support!
- Host: GitHub
- URL: https://github.com/posener/flag
- Owner: posener
- License: mit
- Created: 2017-05-20T18:27:09.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-03-13T18:47:57.000Z (over 4 years ago)
- Last Synced: 2024-10-05T12:42:39.582Z (about 1 month ago)
- Topics: bash-completion, flag, go
- Language: Go
- Homepage:
- Size: 17.6 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# flag
[![Build Status](https://travis-ci.org/posener/flag.svg?branch=master)](https://travis-ci.org/posener/flag)
[![codecov](https://codecov.io/gh/posener/flag/branch/master/graph/badge.svg)](https://codecov.io/gh/posener/flag)
[![GoDoc](https://godoc.org/github.com/posener/flag?status.svg)](http://godoc.org/github.com/posener/flag)
[![Go Report Card](https://goreportcard.com/badge/github.com/posener/flag)](https://goreportcard.com/report/github.com/posener/flag)Like `flag`, but with bash completion support.
## Features
* Fully compatible with standard library `flag` package
* Bash completions for flag names and flag values
* Additional flag types provided:
* [`File`/`Dir`](./flag_path.go): file completion flag
* [`Bool`](./flag_bool.go): bool flag (that does not complete)
* [`Choice`](./flag_choice.go): choices flag
* [`StringCompleter`](./flag_completer.go): custom completions
* Any other value that implements the [`Completer`](./complete.go) interface.## Example
Here is an [example](./example/example.go)
## Usage
```diff
import (
- "flag"
+ "github.com/posener/flag"
)var (
- file = flag.String("file", "", "file value")
+ file = flag.File("file", "*.md", "", "file value")
- dir = flag.String("dir", "", "dir value")
+ dir = flag.Dir("dir", "*", "", "dir value")
b = flag.Bool("bool", false, "bool value")
s = flag.String("any", "", "string value")
- opts = flag.String("choose", "", "some items to choose from")
+ opts = flag.Choice("choose", []string{"work", "drink"}, "", "some items to choose from")
)func main() {
+ flag.SetInstallFlags("complete", "uncomplete")
flag.Parse()
+ if flag.Complete() { // runs bash completion if necessary
+ return // return from main without executing the rest of the command
+ }
...
}
```