Skip to content
/ fflag Public

Go package fflag parses flag.FlagSet from simple configuration files.

License

Notifications You must be signed in to change notification settings

nochso/fflag

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fflag

Go Reference GitHub tag (latest SemVer) GitHub

import "github.com/nochso/fflag"

Package fflag parses [flag.FlagSet] from simple configuration files.

Syntax

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.

Index

Variables

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

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

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

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

type Options

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

func NewDefaultOptions() *Options

NewDefaultOptions returns default options for use in [Parse].

Path:                "config.txt"
ConfigFlagName:      "config"
WriteConfigFlagName: "write-config"

Generated by gomarkdoc

About

Go package fflag parses flag.FlagSet from simple configuration files.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages