A collection of CLI argument types for the Go `flag` package.
Alternatives To Flagvar
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Clap12,0337,66912,824a day ago368July 21, 2023262apache-2.0Rust
A full featured, fast Command Line Argument Parser for Rust
Picocli4,4262092502 days ago83June 03, 2023124apache-2.0Java
Picocli is a modern framework for building powerful, user-friendly, GraalVM-enabled command line apps with ease. It supports colors, autocompletion, subcommands, and more. In 1 source file so apps can include as source & avoid adding a dependency. Written in Java, usable from Groovy, Kotlin, Scala, etc.
Caporal.js3,370669504a month ago17May 11, 202023mitTypeScript
A full-featured framework for building command line applications (cli) with node.js
Clikt2,19229284 days ago16June 20, 202019apache-2.0Kotlin
Multiplatform command line interface parsing for Kotlin
4 months ago20September 29, 20221mitPython
A library for users to write (experiment in research) configurations in Python Dict or JSON format, read and write parameter value via dot . in code, while can read parameters from the command line to modify values. 一个供用户以Python Dict或JSON格式编写(科研中实验)配置的库,在代码中用点.读写属性,同时可以从命令行中读取参数配置并修改参数值。
4 months ago16bsd-3-clauseC++
Argh! A minimalist argument handler.
7 months ago46mitC++
easy to use, powerful & expressive command line argument parsing for modern C++ / single header / usage & doc generation
Mow.cli7871021772 years ago11July 25, 202128mitGo
A versatile library for building CLI applications in Go
Deno Cliffy781
7 days ago28mitTypeScript
Command line framework for deno 🦕 Including Commandline-Interfaces, Prompts, CLI-Table, Arguments Parser and more...
a month ago18mitC
Command-line arguments parsing library.
Alternatives To Flagvar
Select To Compare

Alternative Project Comparisons



A collection of CLI argument types for the flag package.

import "github.com/sgreben/flagvar"

Or just copy & paste what you need. It's public domain.


package main

import (

var (
	fruit    = flagvar.Enum{Choices: []string{"apple", "banana"}}
	urls     flagvar.URLs
	settings flagvar.Assignments

func main() {
	flag.Var(&fruit, "fruit", fmt.Sprintf("set a fruit (%s)", fruit.Help()))
	flag.Var(&urls, "url", "add a URL")
	flag.Var(&settings, "set", fmt.Sprintf("specify a setting (%s)", settings.Help()))
$ go run main.go -set abc=xyz -url https://github.com
# no error

$ go run main.go -set abc=xyz -url ://github.com
invalid value "://github.com" for flag -url: parse ://github.com: missing protocol scheme

$ go run main.go -fruit kiwi
invalid value "kiwi" for flag -fruit: "kiwi" must be one of [apple banana]

$ go run main.go -h
  -fruit value
        set a fruit (one of [apple banana])
  -set value
        specify a setting (a key/value pair KEY=VALUE)
  -url value
        add a URL


  • Pluralized argument types (e.g. Strings, Assignments) can be specified repeatedly, the values are collected in a slice.
  • The resulting value is stored in .Value for singular types and in .Values for plural types
  • The original argument string is stored in .Text for singular types and in .Texts for plural types
  • -Set types (EnumSet, StringSet) de-duplicate provided values.
  • -CSV types (IntsCSV, EnumsCSV) accept comma-separated values and accumulate values across flag instances if their .Accumulate field is set to true.
  • Most types implement interface{ Help() string }, which produces a string suitable for inclusion in a help message.


Here's a compact overview:

flagvar type example CLI arg type of resulting Go value
Assignment KEY=VALUE struct{Key,Value}
Assignments KEY=VALUE []struct{Key,Value}
AssignmentsMap KEY=VALUE map[string]string
CIDR struct{IPNet,IP}
CIDRs []struct{IPNet,IP}
CIDRsCSV, []struct{IPNet,IP}
Enum apple string
Enums apple []string
EnumsCSV apple,banana []string
EnumSet apple []string
EnumSetCSV apple,banana []string
File ./README.md string
Files ./README.md []string
Floats 1.234 []float64
FloatsCSV 1.234,5.0 []float64
Glob src/**.js glob.Glob
Globs src/**.js []glob.Glob
Ints 1002 []int64
IntsCSV 123,1002 []int64
IP net.IP
IPs []net.IP
IPsCSV, []net.IP
JSON '{"a":1}' interface{}
JSONs '{"a":1}' []interface{}
Regexp [a-z]+ *regexp.Regexp
Regexps [a-z]+ []*regexp.Regexp
Strings "xyxy" []string
StringSet "xyxy" []string
StringSetCSV y,x,y []string
TCPAddr net.TCPAddr
TCPAddrs []net.TCPAddr
TCPAddrsCSV,:123 []net.TCPAddr
Template "{{.Size}}" *template.Template
Templates "{{.Size}}" []*template.Template
TemplateFile "/path/to/template.file" string
Time "10:30 AM" time.Time
Times "10:30 AM" []time.Time
TimeFormat "RFC3339" string
UDPAddr net.UDPAddr
UDPAddrs []net.UDPAddr
UDPAddrsCSV,:123 []net.UDPAddr
UnixAddr /example.sock net.UnixAddr
UnixAddrs /example.sock []net.UnixAddr
UnixAddrsCSV /example.sock,/other.sock []net.UnixAddr
URL https://github.com *url.URL
URLs https://github.com []*url.URL

Goals / design principles

  • Help avoid dependencies
    • Self-contained > DRY
    • Explicitly support copy & paste workflow
    • Copyable units should be easy to determine
    • Anonymous structs > shared types
  • "Code-you-own" feeling, even when imported as a package
    • No private fields / methods
    • No magic
    • Simple built-in types used wherever possible
    • Avoid introducing new concepts
  • Support "blind" usage
    • Zero values should be useful
    • Avoid introducing failure cases, handle any combination of parameters gracefully.
    • All "obvious things to try" should work.
Popular Command Line Projects
Popular Argument Parser Projects
Popular Command Line Interface Categories
Related Searches

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Argument Parser