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.
Install Go. Installation instructions here.
$ go get github.com/nibbleshift/argenv
import (
"github.com/nibbleshif/argenv" // imports as package "argenv"
)
...
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)
}
go run main.go -ip-address=192.168.100.1 -port-number=8080 \
-username=steven -shell=/bin/bash -ethernet-device=eth1
(*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"
})
go run main.go -h
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