Skip to content

Commit

Permalink
Added -m (missing) option to allow missing keys
Browse files Browse the repository at this point in the history
  • Loading branch information
stepanstipl committed Aug 12, 2016
1 parent 67266cd commit 3722a86
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ Usage:
confpress [OPTIONS]
Application Options:
-v, --version Show version
-d, --debug Log debug messages
-t, --template= Input template file (- for stdin) (default: -)
-o, --output= Output file (- for stdout) (default: -)
-i, --input= Input variable file(s)
-e, --env_prefix= Environment variables prefix (default: CONF_)
-i, --input= Input variable file(s)
-m, --missing Allow missing keys
-o, --output= Output file (- for stdout) (default: -)
-t, --template= Input template file (- for stdin) (default: -)
-v, --version Show version
Help Options:
-h, --help Show this help message
Expand All @@ -24,5 +25,5 @@ Help Options:
### Examples

- **Reading a variable from yaml/json as shell env variable:**

`MY_VAR=$(echo "{{ .my_variable }}" | confpress -i variables.yaml)`
19 changes: 10 additions & 9 deletions confpress.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@ import (
)

type Options struct {
Version bool `short:"v" long:"version" description:"Show version"`
Debug bool `short:"d" long:"debug" description:"Log debug messages"`
TemplatePath string `short:"t" long:"template" description:"Input template file (- for stdin)" default:"-"`
OutputPath string `short:"o" long:"output" description:"Output file (- for stdout)" default:"-"`

InputPaths []string `short:"i" long:"input" description:"Input variable file(s)"`

EnvPrefix string `short:"e" long:"env_prefix" description:"Environment variables prefix" default:"CONF_"`
InputPaths []string `short:"i" long:"input" description:"Input variable file(s)"`
Missing bool `short:"m" long:"missing" description:"Allow missing keys"`
OutputPath string `short:"o" long:"output" description:"Output file (- for stdout)" default:"-"`
TemplatePath string `short:"t" long:"template" description:"Input template file (- for stdin)" default:"-"`
Version bool `short:"v" long:"version" description:"Show version"`
}

const version=`0.0.1`
const version=`0.1.0`
var opts Options
var parser = flags.NewParser(&opts, flags.Default)
var log = logging.MustGetLogger("default")
Expand Down Expand Up @@ -84,8 +83,10 @@ func main() {
os.Exit(1)
}

// err on missing keys
temp.Option("missingkey=error")
if ! opts.Missing {
// err on missing keys
temp.Option("missingkey=error")
}

log.Infof("Opening output file: '%s'", opts.OutputPath)
outFile, err := createStream(opts.OutputPath)
Expand Down

0 comments on commit 3722a86

Please sign in to comment.