config

package
v2.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 12, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package config handles config files, -config, and env vars at startup.

Index

Constants

View Source
const (
	DEFAULT_CONFIG_FILES = "/etc/spinc/spinc.yaml,~/.spinc.yaml"
	DEFAULT_ADDR         = "http://127.0.0.1:32308"
	DEFAULT_TIMEOUT      = 5000 // 5s
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct {
	Cmd  string   `arg:"positional"`
	Args []string `arg:"positional"`
}

Command represents a command (start, stop, etc.) and its values.

type CommandLine

type CommandLine struct {
	Options
	Command
}

CommandLine represents options (--addr, etc.) and commands (start, etc.). The caller is expected to copy and use the embedded structs separately, like:

var o config.Options = cmdLine.Options
var c config.Command = cmdLine.Command

Some commands and options are mutually exclusive, like --ping and --version. Others can be used together, like --addr and --timeout with any command.

func ParseCommandLine

func ParseCommandLine(def Options) CommandLine

ParseCommandLine parses the command line and env vars. Command line options override env vars. Default options are used unless overridden by env vars or command line options. Defaults are usually parsed from config files.

type Options

type Options struct {
	Addr    string `arg:"env:SPINC_ADDR" yaml:"addr"`
	Config  string `arg:"env:SPINC_CONFIG"`
	Debug   bool   `arg:"env:SPINC_DEBUG" yaml:"debug"`
	Env     string `arg:"env:SPINC_ENV" yaml:"env"`
	Help    bool
	Timeout uint `arg:"env:SPINC_TIMEOUT" yaml:"timeout"`
	Version bool
}

Options represents typical command line options: --addr, --config, etc.

func ParseConfigFiles

func ParseConfigFiles(files string, debug bool) Options

type UserCommandLine added in v2.0.6

type UserCommandLine struct {
	UserOptions
	Command
}

type UserOptions added in v2.0.6

type UserOptions struct {
	Addr    *string
	Config  *string
	Debug   *bool
	Env     *string
	Help    *bool
	Timeout *uint
	Version *bool
}

An Options record for pulling the originally set user arguments

func ParseUserOptions added in v2.0.6

func ParseUserOptions(def UserOptions) UserOptions

Parses the Options explictly set on the command line by the user. Used for allowing reporting on command line needed to re-run a command

func (*UserOptions) ToOptions added in v2.0.6

func (u *UserOptions) ToOptions() Options

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL