Skip to content
/ conf Public

CLI configuration via flags and environment variables

License

Notifications You must be signed in to change notification settings

goph/conf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Conf - CLI configuration management

Build Status Go Report Card GolangCI GoDoc

CLI configuration via flags and environment variables.

Usage

The interface follows closely the flag/pflag packages.

package main

import "github.com/goph/conf"

func main() {
	// Define environment variables and flags using conf.String(), Bool(), Int(), etc.
	var intValue *int = conf.Int("int", 1234, "help message for int")
	
	// If you like, you can bind the environment variable and the flag to a variable using the Var() functions.
	var intVar int
	conf.IntVar(&intVar, "int", 1234, "help message for int")
	
	// Or you can create custom variables that satisfy the Value interface (with pointer receivers)
	// and couple them to variable parsing.
	//
	// For such environment variables/flags, the default value is just the initial value of the variable.
	var intVal conf.Value
	conf.Var(&intVal, "int", "help message for int")
	
	// If you prefer only environment variables or flags as a source for certain values,
	// you can use the above methods with the "E" and "F" suffix.
	intValue = conf.IntF("int", 1234, "help message for int")
	intValue = conf.IntE("int", 1234, "help message for int")
	
	// After all variables are defined.
	conf.Parse()
}

Development

dep is required to install dependencies:

$ make dep # dep ensure

When all coding and testing is done, please run the test suite:

$ make test # go test

For linting we use GolangCI.

$ make lint # golangci-lint run

You can run the whole suite with:

$ make check

License

The MIT License (MIT). Please see License File for more information.

This project is heavily inspired by flag/pflag packages.

About

CLI configuration via flags and environment variables

Resources

License

Stars

Watchers

Forks

Packages

No packages published