Skip to content

raiiga/flagg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GoDoc Go Report Card

Description:

Flagg is a CLI library for parsing command-line arguments in Go.

It is designed to be intuitive, easy to use and suitable for cases where usage of e.g. spf13/cobra, urfave/cli, etc. may be excessive.

Example:

package main

import (
	"fmt"
	"github.com/raiiga/flagg"
)

type options struct {
	input   string `flagg:"n:i, name:input, usage:Input file path"`
	output  string `flagg:"n:o, name:output, usage:Output file path"`
	version bool   `flagg:"n:v, name:version, usage:Print version"`
	verbose bool   `flagg:"n:V, name:verbose, usage:Verbose output mode"`
}

func main() {
	opts, flags := new(options), flagg.New("Usage: app [options]")

	if err := flags.Map(opts); err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(*opts)
}

Output:

$ go build -o example ./main.go

$ ./example -h
Usage: app [options]
  -i, --input      Input file path
  -o, --output     Output file path
  -v, --version    Print version
  -V, --verbose    Verbose output mode
  
$ ./example --help
Usage: app [options]
  -i, --input      Input file path
  -o, --output     Output file path
  -v, --version    Print version
  -V, --verbose    Verbose output mode
  
$ ./example -i /etc/hosts -o out.log --verbose
{/etc/hosts out.log false true}

About

Library for parsing command-line arguments in Go

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages