cord-776 create build / runtime containers for autmation uservices
Change-Id: I246973192adef56a250ffe93a5f65fff488840c1
diff --git a/harvester/harvester.go b/harvester/harvester.go
index 7e10599..e0314e6 100644
--- a/harvester/harvester.go
+++ b/harvester/harvester.go
@@ -14,11 +14,13 @@
package main
import (
+ "flag"
"fmt"
"github.com/Sirupsen/logrus"
"github.com/gorilla/mux"
"github.com/kelseyhightower/envconfig"
"net/http"
+ "os"
"regexp"
"strconv"
"strings"
@@ -27,6 +29,8 @@
"time"
)
+const appName = "HARVESTER"
+
// application application configuration and internal state
type application struct {
Port int `default:"4246" desc:"port on which the service will listen for requests"`
@@ -50,6 +54,7 @@
BadClientNames []string `default:"localhost" envconfig:"BAD_CLIENT_NAMES" desc:"list of invalid hostnames for clients"`
ClientNameTemplate string `default:"UKN-{{with $x:=.HardwareAddress|print}}{{regex $x \":\" \"\"}}{{end}}" envconfig:"CLIENT_NAME_TEMPLATE" desc:"template for generated host name"`
+ appFlags *flag.FlagSet `ignored:"true"`
log *logrus.Logger `ignored:"true"`
interchange sync.RWMutex `ignored:"true"`
leases map[string]*Lease `ignored:"true"`
@@ -62,12 +67,25 @@
}
func main() {
+
// initialize application state
app := &application{
log: logrus.New(),
+ appFlags: flag.NewFlagSet("", flag.ContinueOnError),
requests: make(chan *chan uint, 100),
}
+ app.appFlags.Usage = func() {
+ envconfig.Usage(appName, app)
+ }
+ if err := app.appFlags.Parse(os.Args[1:]); err != nil {
+ if err != flag.ErrHelp {
+ os.Exit(1)
+ } else {
+ return
+ }
+ }
+
// process and validate the application configuration
err := envconfig.Process("HARVESTER", app)
if err != nil {