https://github.com/nochso/fflag
Go package fflag parses flag.FlagSet from simple configuration files.
https://github.com/nochso/fflag
Last synced: 10 months ago
JSON representation
Go package fflag parses flag.FlagSet from simple configuration files.
- Host: GitHub
- URL: https://github.com/nochso/fflag
- Owner: nochso
- License: mit
- Created: 2022-03-07T22:00:21.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-08-06T19:39:17.000Z (almost 4 years ago)
- Last Synced: 2024-06-20T06:31:34.817Z (almost 2 years ago)
- Language: Go
- Size: 33.2 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# fflag
[](https://pkg.go.dev/github.com/nochso/fflag)


```go
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](<#variables>)
- [func Parse(fs *flag.FlagSet, o *Options) error](<#func-parse>)
- [func ParseArgs(fs *flag.FlagSet, o *Options, args []string) error](<#func-parseargs>)
- [func WriteFlagSetConfig(w io.Writer, fs *flag.FlagSet, ignoreFlags ...string)](<#func-writeflagsetconfig>)
- [type Options](<#type-options>)
- [func NewDefaultOptions() *Options](<#func-newdefaultoptions>)
## Variables
ErrWriteConfig is returned by \[Parse\] after the current configuration has been to written to \[os.Stdout\].
```go
var ErrWriteConfig = errors.New("wrote configuration to stdout")
```
## func Parse
```go
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
```go
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
```go
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.
```go
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
```go
func NewDefaultOptions() *Options
```
NewDefaultOptions returns default options for use in \[Parse\].
```
Path: "config.txt"
ConfigFlagName: "config"
WriteConfigFlagName: "write-config"
```
Generated by [gomarkdoc]()