An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

          

# fflag

[![Go Reference](https://pkg.go.dev/badge/github.com/nochso/fflag.svg)](https://pkg.go.dev/github.com/nochso/fflag)
![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/nochso/fflag?sort=semver)
![GitHub](https://img.shields.io/github/license/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]()