Skip to content

Commit

Permalink
Using --no-sys-env
Browse files Browse the repository at this point in the history
  • Loading branch information
subchen committed Feb 28, 2019
1 parent 1d4523b commit 1a5745f
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,22 @@ var (
LoadFileList []string
Overwrite bool
Dryrun bool
Noenv bool
NoSysEnv bool
Delims string
)

// create template context
func newTemplateVariables(noenv bool) map[string]interface{} {
func newTemplateVariables() map[string]interface{} {

var vars = make(map[string]interface{})

// Env
if noenv == false {
if !NoSysEnv {
envs := make(map[string]interface{})
for _, env := range os.Environ() {
kv := strings.SplitN(env, "=", 2)
envs[kv[0]] = kv[1]
envs[kv[0]] = kv[1] // .Env.name
vars[kv[0]] = kv[1] // override using system env in root scope
}
vars["Env"] = envs
}
Expand Down Expand Up @@ -195,9 +196,9 @@ func main() {
Value: &Dryrun,
},
{
Name: "no-env",
Usage: "not include environments, default false",
Value: &Noenv,
Name: "no-sys-env",
Usage: "exclude system environments, default false",
Value: &NoSysEnv,
},
{
Name: "delims",
Expand Down Expand Up @@ -245,7 +246,7 @@ echo "{{ .Env.PATH }}" | frep -
t = t.Delims(pairs[0], pairs[1])
}

vars := newTemplateVariables(c.IsSet("noenv"))
vars := newTemplateVariables()

for _, file := range c.Args() {
templateExecute(t, file, vars)
Expand Down

0 comments on commit 1a5745f

Please sign in to comment.