Created
September 26, 2016 19:06
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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