8000 GitHub - posener/flag: Like the flag package, but with bash completion support!
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

posener/flag

Repository files navigation

flag

Build Status codecov GoDoc Go Report Card

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:

Example

Here is an example

Usage

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
+	}
    ...
}

About

Like the flag package, but with bash completion support!

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  
0