Skip to content

nibbleshift/argenv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ArgEnv

ArgEnv is a simple package for quickly loading command line parameters, environment variables, and default settings in your app.

The goal is to simplify loading configurable settings in your application.

Usage Documentation

Installation

Install Go. Installation instructions here.

Get the package

$ go get github.com/nibbleshift/argenv
import (
  "github.com/nibbleshif/argenv" // imports as package "argenv"
)
...

Example

package main

import (
	"github.com/davecgh/go-spew/spew"
	"gitlab.com/nibbleshift/argenv"
)

type MySettings struct {
	EthernetDevice string `default: "eth0" description:"Specify NIC to configure"`
	IpAddress      string `default: "127.0.0.1" description:"IP Address to listen on"`
	PortNumber     int    `default: "80" description:"IP Address to listen on"`
	Username       string `default: "root" description:"Default user"`
	Shell          string `default: "/bin/bash" description:"Default Shell"`
}

var settings *MySettings

func main() {
	argEnv := &argenv.ArgEnv{}
	settings = &MySettings{}

	argEnv.Load(settings)
	spew.Dump(settings)
}

Running Example:

go run main.go -ip-address=192.168.100.1 -port-number=8080 \
	-username=steven -shell=/bin/bash -ethernet-device=eth1

Output

(*main.MySettings)(0xc000074190)({
 EthernetDevice: (string) (len=4) "eth1",
 IpAddress: (string) (len=13) "192.168.100.1",
 PortNumber: (int) 8080,
 Username: (string) (len=6) "steven",
 Shell: (string) (len=9) "/bin/bash"
})

Running Example Usage:

go run main.go -h

Output

ArgEnv Usage of /tmp/go-build1573678449/b001/exe/main:
  -ethernet-device string
        Specify NIC to configure (default "eth0")
  -ip-address string
        IP Address to listen on (default "127.0.0.1")
  -port-number int
        IP Address to listen on (default 80)
  -shell string
        Default Shell (default "/bin/bash")
  -username string
        Default user (default "root")
Available Environment Variables:
        ETHERNET_DEVICE
        IP_ADDRESS
        PORT_NUMBER
        USERNAME
        SHELL

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages