All Projects → lukechampine → flagg

lukechampine / flagg

Licence: MIT license
Barebones subcommand handling

Programming Languages

go
31211 projects - #10 most used programming language

Labels

Projects that are alternatives of or similar to flagg

React Intl Tel Input
Rewrite International Telephone Input in React.js. (Looking for maintainers, and PRs & contributors are also welcomed!)
Stars: ✭ 212 (+285.45%)
Mutual labels:  flags
envflag
Simple environment-variables extension to Golang flag.
Stars: ✭ 21 (-61.82%)
Mutual labels:  flags
graphcountries
An easy to use GraphQL API to query country-related data for free and without restrictions
Stars: ✭ 61 (+10.91%)
Mutual labels:  flags
Config
📝 Go config manage(load,get,set). support JSON, YAML, TOML, INI, HCL, ENV and Flags. Multi file load, data override merge, parse ENV var. Go应用配置加载管理,支持多种格式,多文件加载,远程文件加载,支持数据合并,解析环境变量名
Stars: ✭ 225 (+309.09%)
Mutual labels:  flags
fastHistory
A python tool connected to your terminal to store important commands, search them in a fast way and automatically paste them into your terminal
Stars: ✭ 24 (-56.36%)
Mutual labels:  flags
flagpack
A lightweight flag icon toolkit for the web.
Stars: ✭ 51 (-7.27%)
Mutual labels:  flags
Countrycode
🎯 Swift country and phone code Picker
Stars: ✭ 175 (+218.18%)
Mutual labels:  flags
c-compiler-security
Security-related flags and options for C compilers
Stars: ✭ 125 (+127.27%)
Mutual labels:  flags
cleye
👁‍🗨 cleye — The intuitive & typed CLI development tool for Node.js
Stars: ✭ 235 (+327.27%)
Mutual labels:  flags
uconfig
Lightweight, zero-dependency, and extendable configuration management library for Go
Stars: ✭ 53 (-3.64%)
Mutual labels:  flags
Quiz
Ex 1 - Run timed quizzes via the command line
Stars: ✭ 234 (+325.45%)
Mutual labels:  flags
country-flags
A small package to convert a country code to the corresponding country flag emoji
Stars: ✭ 27 (-50.91%)
Mutual labels:  flags
ld-scheduler
Schedule Launch Darkly flags on or off
Stars: ✭ 14 (-74.55%)
Mutual labels:  flags
Flaeg
golang CLI with magic
Stars: ✭ 222 (+303.64%)
Mutual labels:  flags
ld-redux
A library to integrate launch darkly with react redux
Stars: ✭ 33 (-40%)
Mutual labels:  flags
Go Flagz
Dynamic flag management for Go.
Stars: ✭ 191 (+247.27%)
Mutual labels:  flags
PhoneCountryCodePicker
An iOS tableview picker for PhoneCountryCode (English & Chinese supported)
Stars: ✭ 31 (-43.64%)
Mutual labels:  flags
react-circle-flags
🚀 A React component with a collection of 300+ minimal circular SVG country flags. Wrapper of HatScripts/circle-flags
Stars: ✭ 29 (-47.27%)
Mutual labels:  flags
vue-flagpack
Flagpack contains 260+ easily implementable flag icons to use in your design or code project.
Stars: ✭ 42 (-23.64%)
Mutual labels:  flags
cli
a lightweight and simple cli package
Stars: ✭ 12 (-78.18%)
Mutual labels:  flags

flagg

GoDoc Go Report Card

go get lukechampine.com/flagg

flagg is a tiny package that makes it easier to build CLI apps that use subcommands. I built it because the stdlib flag package is too low-level, but popular alternatives like spf13/cobra are full-fledged frameworks with too many bells and whistles for my liking. flagg is 67 lines of code and imports only stdlib packages.

flagg is designed around the stdlib *flag.FlagSet type. You represent each subcommand in your app with a *flag.FlagSet, and arrange them into a hierarchy with flagg.Tree. Then just call flagg.Parse to parse the subcommand selected by os.Args.

Example

// commands are just *flag.FlagSets
var rootCmd *flag.FlagSet = flagg.Root
rootCmd.Usage = flagg.SimpleUsage(rootCmd, "An example program")
verbose := rootCmd.Bool("v", false, "display verbose output")

// flagg.New constructs a *flag.FlagSet with the given name and usage
// description
fooCmd := flagg.New("foo", "The foo subcommand")
bars := fooCmd.Int("bars", 0, "number of bars to foo")
quuxCmd := flagg.New("quux", "The quux subcommand")

// construct the command hierarchy
tree := flagg.Tree{
	Cmd: rootCmd,
	Sub: []flagg.Tree{
		{Cmd: fooCmd},
		{Cmd: quuxCmd},
	},
}

// Parse the command hierarchy. cmd is the selected command, e.g. if
// os.Args = []string{"./example", "quux"}, then cmd == quuxCmd.
cmd := flagg.Parse(tree)

// again, cmd is just a *flag.FlagSet, so Args() returns the arguments of the
// selected command.
args := cmd.Args()

// use a switch to identify the cmd that was selected
switch cmd {
case fooCmd:
	fmt.Printf("fooing %v bars\n", *bars)
case quuxCmd:
	fmt.Println("quux!", args)
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].