import "github.com/nochso/fflag"
Package fflag parses [flag.FlagSet] from simple configuration files.
Keys (flag names without the "-" prefix) followed by values.
flag-name flag-value
Comments begin with any of these: # ; //
Leading and trailing whitespace is ignored on each line, key and value.
- Variables
- func Parse(fs *flag.FlagSet, o *Options) error
- func ParseArgs(fs *flag.FlagSet, o *Options, args []string) error
- func WriteFlagSetConfig(w io.Writer, fs *flag.FlagSet, ignoreFlags ...string)
- type Options
ErrWriteConfig is returned by [Parse] after the current configuration has been to written to [os.Stdout].
var ErrWriteConfig = errors.New("wrote configuration to stdout")
func Parse(fs *flag.FlagSet, o *Options) error
Parse a config file using [os.Args] into an existing [flag.FlagSet] before parsing the FlagSet itself.
Returns [ErrWriteConfig] if the configuration was written to stdout as requested.
func ParseArgs(fs *flag.FlagSet, o *Options, args []string) error
ParseArgs parses a config file using given arguments into an existing [flag.FlagSet] before parsing the FlagSet itself.
Returns [ErrWriteConfig] if the configuration was written to stdout as requested.
func WriteFlagSetConfig(w io.Writer, fs *flag.FlagSet, ignoreFlags ...string)
WriteFlagSetConfig writes a configuration file to w including both default and currently set values (should they differ).
Options used for parsing a config file.
type Options struct {
// Path is the default config file path.
//
// If this file does exist, no error is returned.
// If a specific file is given using FlagName, the file must exist.
Path string
// ConfigFlagName is the name of the flag that points to a config file.
//
// If this flag is invoked a non-existing file will return an error.
ConfigFlagName string
// WriteConfigFlagName is the name of the flag that causes the current
// configuration to be printed.
WriteConfigFlagName string
}
func NewDefaultOptions() *Options
NewDefaultOptions returns default options for use in [Parse].
Path: "config.txt"
ConfigFlagName: "config"
WriteConfigFlagName: "write-config"
Generated by gomarkdoc