Skip to content

Talos208/conflag

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

conflag Build Status

A combination command-line flag and configuration file library for Go.

Usage

// define your flags.
var procs int
flag.IntVar(&procs, "procs", runtime.NumCPU(), "GOMAXPROCS")

// set flags from configuration before parse command-line flags.
if args, err := conflag.ArgsFrom("/path/to/config.toml"); err == nil {
	flag.CommandLine.Parse(args)
}

// parse command-line flags.
flag.Parse()

and you create /path/to/config.toml

procs = 2

and run your app without option, procs flag will be set in 2 that is defined at configration file.

Priority of flag

A priority of flag is

command-line flag > configration file > flag default value

In the above case,

run procs
myapp -procs 3 3
myapp (with config-file) 2
myapp (without config-file) runtime.NumCPU() (default of flag)

Position

You can specify positions arguments to ArgsFrom function.

[options]
flag = "value"

[other settings]
hoge = "fuga"
// parse configration only under the options section.
conflag.ArgsFrom("/path/to/config.toml", "options")

Features

  • Combine command-line flag and configuration file.
  • Specify configration section.
  • Support TOML configuration file.
  • Support JSON configuration file.

Installation

$ go get github.com/monochromegane/conflag

Contribution

  1. Fork it
  2. Create a feature branch
  3. Commit your changes
  4. Rebase your local changes against the master branch
  5. Run test suite with the go test ./... command and confirm that it passes
  6. Run gofmt -s
  7. Create new Pull Request

License

MIT

Author

monochromegane

About

A combination command-line flag and configuration file library for Go.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%