Skip to content

Instantly share code, notes, and snippets.

@maplebed
Created September 26, 2016 19:06
Show Gist options
  • Save maplebed/130dfafb4fc61cc2becfd31af060fef2 to your computer and use it in GitHub Desktop.
Save maplebed/130dfafb4fc61cc2becfd31af060fef2 to your computer and use it in GitHub Desktop.
Sample code testing use of an ini file with go-flags - config file is string
package main
import (
"fmt"
flag "github.com/jessevdk/go-flags"
)
type Opts struct {
TestFlag string `short:"t" description:"just here to aid in testing ini files and defaults" default:"default"`
// ConfigFile string `short:"c" long:"config" description:"config file for in ini format" no-ini:"true"`
ConfigFile string `short:"c" long:"config" description:"config file for in ini format" no-ini:"true" default:"ft.ini"`
}
func main() {
var opts Opts
fp := flag.NewParser(&opts, flag.PrintErrors)
fp.Parse()
// read the config file if present
ini := flag.NewIniParser(fp)
ini.ParseAsDefaults = true
ini.ParseFile(opts.ConfigFile)
fmt.Printf("options: %+v\n", opts)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment