Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/ianschenck/envflag

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/ianschenck/envflag

  • v0.0.0-20140720210342-9111d830d133
  • Source
  • Go
  • Socket score

Version published
Created
Source

envflag

Golang flags, but bolted onto the environment rather than the command-line.

Read the godocs.

Motivation

Some like the distinction that command-line flags control behavior while environment variables configure. Also 12-factor recommends the use of environment variables for configuration. The interface of the golang flag package is well designed and easy to use, and allows for other lists (os.Environ() vs os.Args) to be parsed as flags. It makes sense then to use the same interface, the same types, and the same parsing (caveat: there is some ugly string hacking to make environment variables look like flags) to the same ends.

Differences

Calling flag.Parse() will not parse environment flags. Calling envflag.Parse() will not parse command-line flags. There is no good reason to combine these two when the net savings is a single line in a func main(). Furthermore, doing so would require users to accept a precedence order of my choosing.

The presence of an environment variable named h or help will probably cause problems (print Usage and os.Exit(0)). Work around this by defining those flags somewhere (and ignoring them).

Before calling Flagset.Parse on EnvironmentFlags, the environment variables being passed to Parse are trimmed down using Lookup. This behavior is different from flag.Parse in that extra environment variables are ignored (and won't crash envflag.Parse).

FAQs

Package last updated on 20 Jul 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc