Skip to content

Commit

Permalink
renamed allowlist to --filter and added --prefix flag
Browse files Browse the repository at this point in the history
  • Loading branch information
michielvermeir committed Jan 3, 2024
1 parent 5ebe811 commit a4e8a57
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
26 changes: 14 additions & 12 deletions cmd/svart/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ type arg[T string | bool] struct {
}

type Args struct {
AllowlistFile arg[string]
File arg[string]
FromEnv arg[bool]
FromStdin arg[bool]
Relaxed arg[bool]
Version arg[bool]
File arg[string]
Filter arg[string]
FromEnv arg[bool]
FromStdin arg[bool]
Prefix arg[string]
Relaxed arg[bool]
Version arg[bool]
}

func define[T string | bool](name string, value *T) arg[T] {
Expand All @@ -31,12 +32,13 @@ func define[T string | bool](name string, value *T) arg[T] {

func InitializeCommandLine() *Args {
args := &Args{
AllowlistFile: define[string]("allowlist-file", flag.String("allowlist", "", "only re-export allowlisted variables")),
File: define[string]("from-file", flag.String("from-file", "", "read from file")),
FromEnv: define[bool]("from-env", flag.Bool("from-env", true, "read from environment variables")),
FromStdin: define[bool]("from-stdin", flag.Bool("from-stdin", false, "read from stdin")),
Relaxed: define[bool]("relaxed", flag.Bool("relaxed", false, "allows ALL variables to be re-exported")),
Version: define[bool]("version", flag.Bool("version", false, "print version")),
File: define[string]("from-file", flag.String("from-file", "", "read from file")),
Filter: define[string]("filter", flag.String("filter", "", "filter input variables")),
FromEnv: define[bool]("from-env", flag.Bool("from-env", true, "read from environment variables")),
FromStdin: define[bool]("from-stdin", flag.Bool("from-stdin", false, "read from stdin")),
Prefix: define[string]("prefix", flag.String("prefix", "", "prefix to add to each variable")),
Relaxed: define[bool]("relaxed", flag.Bool("relaxed", false, "allows ALL variables to be re-exported")),
Version: define[bool]("version", flag.Bool("version", false, "print version")),
}

// Must parse after all flags are defined
Expand Down
8 changes: 6 additions & 2 deletions cmd/svart/svart.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ func main() {

os.Setenv("SVART_RELAXED_MODE", strconv.FormatBool(*args.Relaxed.Value))

if *args.AllowlistFile.Value != "" {
os.Setenv("SVART_ALLOWLIST_FILE", *args.AllowlistFile.Value)
if *args.Prefix.Value != "" {
os.Setenv("SVART_PREFIX", *args.Prefix.Value)
}

if *args.Filter.Value != "" {
os.Setenv("SVART_ALLOWLIST_FILE", *args.Filter.Value)
}

inputs := GetCommandLineInputs(args)
Expand Down

0 comments on commit a4e8a57

Please sign in to comment.