Git Product home page Git Product logo

conflag's Introduction

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")

List

You can use list for multiple parameters. The following toml makes -flag value1 -flag value2 arguments.

flag = [ "value1", "value2" ]

go-flags

If you use go-flags package, you can specify options like the following.

parser := go-flags.NewParser(&opts, go-flags.Default)

conflag.LongHyphen = true
conflag.BoolValue = false
if args, err := conflag.ArgsFrom("/path/to/config.toml"); err == nil {
        parser.ParseArgs(args)
}

Features

  • Combine command-line flag and configuration file.
  • Specify configration section.
  • Specify list parameters.
  • Support TOML configuration file.
  • Support JSON configuration file.
  • Support YAML 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

conflag's People

Contributors

mathhun avatar monochromegane avatar talos208 avatar walf443 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.