Documentation ¶
Index ¶
- Constants
- Variables
- func Copy(src, dst string) error
- func FormatKey(prefix, keyWithPrefix string) string
- func GetTemplate(fileName string) (s string, err error)
- func GetTemplateParams(value string) (params []string)
- func KeyExtensionsDir(prefix string) string
- func KeyPrefixExtensions(prefix string) string
- func KeyPrefixTemplate(prefix string) string
- func Main(version string)
- func MarshalENV(c *conf) (b []byte, err error)
- func ReadConfigFile(appDir, env string) (configPath string, b []byte, err error)
- func ToPrivate(str string) string
- func UnmarshalENV(b []byte) (m map[string]string, err error)
- type ArgMap
- type CmdIn
- type CmdInParams
- type CmdOut
- type File
- type Files
- type GenerateData
- type GenerateKey
- type TemplateKey
- type TemplateParam
Constants ¶
const ( CmdBase64 = "base64" CmdCompare = "compare" CmdCSV = "csv" CmdGenerate = "generate" CmdGet = "get" CmdSetEnv = "set-env" CmdUpdateConfig = "update-config" CmdVersion = "version" )
const ( FlagAll = "all" FlagBase64 = "base64" FlagCompare = "compare" FlagCSV = "csv" FlagDel = "del" FlagDryRun = "dry-run" FlagEnv = "env" FlagExtend = "extend" FlagGenerate = "generate" FlagGet = "get" FlagKey = "key" FlagMerge = "merge" FlagPrefix = "prefix" FlagSep = "sep" FlagValue = "value" FlagVersion = "version" FlagOS = "os" FlagFormat = "format" )
const ExportFormat = OtherExportFormat
const FileNameConfigGo = "config.go"
FileNameConfigGo for config.go
const FileNameFnGo = "fn.go"
FileNameFnGo for fn.go
const FileNameTemplateGo = "template.go"
FileNameTemplateGo for template.go
const FileTypeEnv = ".env" // e.g. .env
const FileTypeJSON = ".json" // e.g. config.json
const FileTypeYAML = ".yaml" // e.g. config.yaml
const LineBreak = OtherLineBreak
const OtherExportFormat = "export %v=%v"
const OtherLineBreak = "\n"
const OtherUnsetFormat = "unset %v"
const SamplePrefix = "sample."
const UnsetFormat = OtherUnsetFormat
const WindowsExportFormat = "set %v=%v"
Note the difference between set and setx https://superuser.com/a/916652/537059
const WindowsLineBreak = "\r\n"
const WindowsUnsetFormat = "set %v=\"\""
Variables ¶
var ErrCmdConfig = errors.NewCause("cmdconfig")
var ErrDuplicateKey = func(key string) error { return errors.NewWithCausef(ErrCmdConfig, "duplicate key %s", key) }
var ErrMissingKey = func(key string) error { return errors.NewWithCausef(ErrCmdConfig, "missing key %s", key) }
var ErrNotImplemented = errors.NewWithCausef(ErrCmdConfig, "not implemented")
var ErrParentNotFound = errors.NewWithCausef( ErrCmdConfig, "parent config not found")
Functions ¶
func Copy ¶ added in v0.5.0
Copy the src file to dst. Return an error if dst exists. Inspired by https://stackoverflow.com/a/21061062/639133
func FormatKey ¶ added in v0.4.0
FormatKey removes the prefix and converts env var to golang var, e.g. APP_FOO_BAR becomes FooBar
func GetTemplate ¶ added in v0.5.0
GetTemplate returns the text template for the given file name.
func GetTemplateParams ¶ added in v0.4.0
GetTemplateParams from template, e.g. passing in "Fizz{{.Buz}}{{.Meh}}" should return ["Buz", "Meh"]
func KeyExtensionsDir ¶ added in v0.12.0
func KeyPrefixExtensions ¶ added in v0.12.0
func KeyPrefixTemplate ¶ added in v0.12.0
func Main ¶
func Main(version string)
Main function for cmd/configu. The configu command can be customized by copying the code below. Try not to change the default behaviour, e.g. custom flags must only add functionality
func MarshalENV ¶ added in v0.9.0
MarshalENV key value map to .env file bytes
func ReadConfigFile ¶ added in v0.9.0
func UnmarshalENV ¶ added in v0.9.0
UnmarshalENV .env file bytes to key value map. Syntax rules as per this comment https://github.com/mozey/config/issues/24#issue-1091975787
Types ¶
type CmdIn ¶
type CmdIn struct { // AppDir is the application root AppDir string // Prefix for env vars Prefix string // PrintVersion for printing the build version PrintVersion bool // Env selects the config file Env string // All makes the cmd apply to all config files in APP_DIR, including samples // https://github.com/mozey/config/issues/2 All bool // Del deletes the specified keys Del bool // Compare config file keys Compare string // Keys to update Keys ArgMap // Value to update Values ArgMap // PrintValue for the given key PrintValue string // Generate config helper Generate string CSV bool Sep string DryRun bool // Base64 encode config file Base64 bool // OS overrides the compiled x-platform config OS string // Override config file format Format string // Extend config Extend ArgMap // Merge with parent config Merge bool // contains filtered or unexported fields }
CmdIn for use with command functions
func NewCmdIn ¶ added in v0.10.0
func NewCmdIn(params CmdInParams) *CmdIn
NewCmdIn constructor for CmdIn
type CmdInParams ¶ added in v0.10.0
type CmdInParams struct { // Version to print with the version flag Version string }
type CmdOut ¶
type CmdOut struct { // Cmd is the unique command that was executed Cmd string // ExitCode can be non-zero if the err returned is nil, // that means the program did not have any internal error, // but the command "failed", i.e. non-zero exit code ExitCode int // Buf of cmd output Buf *bytes.Buffer // Files to write if in.DryRun is not set Files Files }
CmdOut for use with Cmd function
type Files ¶ added in v0.5.0
type Files []File
type GenerateData ¶ added in v0.4.0
type GenerateData struct { Prefix string AppDir string Keys []GenerateKey TemplateKeys []TemplateKey // KeyMap can be used to lookup an index in Keys given a key KeyMap map[string]int }
func NewGenerateData ¶ added in v0.4.0
func NewGenerateData(in *CmdIn) (data *GenerateData, err error)
type GenerateKey ¶ added in v0.4.0
type TemplateKey ¶
type TemplateKey struct { GenerateKey ExplicitParams string Params []TemplateParam }
TemplateKey, e.g. APP_TEMPLATE_*