Skip to content

feat: make all cli flags available as env variables (opt-in) #3

Description

@mfridman

This might not be necessary since it's just a few helper functions most users can stub out in their code, e.g.,

func getFlagOrEnv(s *cli.State, name string, envPrefix string) (string, error) {
	envName := strings.ToUpper(name)
	val := cmp.Or(
		cli.GetFlag[string](s, name),
		os.Getenv(envPrefix+envName),
	)
	if val == "" {
		return "", fmt.Errorf("must provide --%s flag or set %s environment variable", name, envName)
	}
	return val, nil
}

We could optionally bake this logic into the cli library or add a cli.GetFlagOrEnv helper function.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions