summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2015-12-31 13:18:50 (GMT)
committerChristian Pointner <equinox@helsinki.at>2015-12-31 13:18:50 (GMT)
commit26f2b95168cab463e094a13991b8a486a68e684f (patch)
tree1ca60930d97b84edf28e88ceddd5b8806735b60e /src
parentec5bc3996e3abbdb56494ccb2b4115d976022dcc (diff)
all command line arguments can now be set using environment variables
Diffstat (limited to 'src')
-rw-r--r--src/helsinki.at/rhimport/conf.go10
-rw-r--r--src/helsinki.at/rhimportd/main.go44
2 files changed, 40 insertions, 14 deletions
diff --git a/src/helsinki.at/rhimport/conf.go b/src/helsinki.at/rhimport/conf.go
index d628563..59308a9 100644
--- a/src/helsinki.at/rhimport/conf.go
+++ b/src/helsinki.at/rhimport/conf.go
@@ -68,15 +68,15 @@ func (self *Config) readConfigFile() error {
return nil
}
-func NewConfig(configfile, rdxportEndpoint, tempDir, localFetchDir *string) (conf *Config, err error) {
+func NewConfig(configfile, rdxportEndpoint, tempDir, localFetchDir string) (conf *Config, err error) {
conf = new(Config)
- conf.configfile = *configfile
+ conf.configfile = configfile
if err = conf.readConfigFile(); err != nil {
return
}
- conf.RDXportEndpoint = *rdxportEndpoint
- conf.TempDir = *tempDir
- conf.LocalFetchDir = *localFetchDir
+ conf.RDXportEndpoint = rdxportEndpoint
+ conf.TempDir = tempDir
+ conf.LocalFetchDir = localFetchDir
conf.ImportParamDefaults.Channels = 2
conf.ImportParamDefaults.NormalizationLevel = -12
conf.ImportParamDefaults.AutotrimLevel = 0
diff --git a/src/helsinki.at/rhimportd/main.go b/src/helsinki.at/rhimportd/main.go
index 3d5c0b1..c6090cb 100644
--- a/src/helsinki.at/rhimportd/main.go
+++ b/src/helsinki.at/rhimportd/main.go
@@ -26,6 +26,7 @@ package main
import (
"flag"
+ "fmt"
"helsinki.at/rhimport"
"log"
"os"
@@ -40,13 +41,38 @@ var (
//rhdl = log.New(ioutil.Discard, "[rhimportd-dbg]\t", log.LstdFlags)
)
+type envStringValue string
+
+func newEnvStringValue(key, dflt string) *envStringValue {
+ if envval, exists := os.LookupEnv(key); exists {
+ return (*envStringValue)(&envval)
+ } else {
+ return (*envStringValue)(&dflt)
+ }
+}
+
+func (s *envStringValue) Set(val string) error {
+ *s = envStringValue(val)
+ return nil
+}
+
+func (s *envStringValue) Get() interface{} { return string(*s) }
+
+func (s *envStringValue) String() string { return fmt.Sprintf("%s", *s) }
+
func main() {
- webAddr := flag.String("web-addr", ":4080", "addr:port to listen on")
- telnetAddr := flag.String("telnet-addr", ":4023", "addr:port to listen on")
- rdconf := flag.String("rdconf", "/etc/rd.conf", "path to the Rivendell config file")
- rdxportUrl := flag.String("rdxport-url", "http://localhost/rd-bin/rdxport.cgi", "the url to the Rivendell web-api")
- tempDir := flag.String("tmp-dir", os.TempDir(), "path to temporary files")
- localFetchDir := flag.String("local-fetch-dir", os.TempDir(), "path to files that can be imported using local://")
+ webAddr := newEnvStringValue("RHIMPORTD_WEB_ADDR", "localhost:4080")
+ flag.Var(webAddr, "web-addr", "addr:port to listen on (environment: RHIMPORTD_WEB_ADDR)")
+ telnetAddr := newEnvStringValue("RHIMPORTD_TELNET_ADDR", "localhost:4023")
+ flag.Var(telnetAddr, "telnet-addr", "addr:port to listen on (environment: RHIMPORTD_TELNET_ADDR)")
+ rdconf := newEnvStringValue("RHIMPORTD_RD_CONF", "/etc/rd.conf")
+ flag.Var(rdconf, "rdconf", "path to the Rivendell config file (environment: RHIMPORTD_RD_CONF)")
+ rdxportUrl := newEnvStringValue("RHIMPORTD_RDXPORT_URL", "http://localhost/rd-bin/rdxport.cgi")
+ flag.Var(rdxportUrl, "rdxport-url", "the url to the Rivendell web-api (environment: RHIMPORTD_RDXPORT_URL)")
+ tempDir := newEnvStringValue("RHIMPORTD_TEMP_DIR", os.TempDir())
+ flag.Var(tempDir, "tmp-dir", "path to temporary files (environment: RHIMPORTD_TEMP_DIR)")
+ localFetchDir := newEnvStringValue("RHIMPORTD_LOCAL_FETCH_DIR", os.TempDir())
+ flag.Var(localFetchDir, "local-fetch-dir", "base path for local:// urls (environment: RHIMPORTD_LOCAL_FETCH_DIR)")
help := flag.Bool("help", false, "show usage")
flag.Parse()
@@ -55,7 +81,7 @@ func main() {
return
}
- conf, err := rhimport.NewConfig(rdconf, rdxportUrl, tempDir, localFetchDir)
+ conf, err := rhimport.NewConfig(rdconf.Get().(string), rdxportUrl.Get().(string), tempDir.Get().(string), localFetchDir.Get().(string))
if err != nil {
rhl.Println("Error reading configuration:", err)
return
@@ -81,7 +107,7 @@ func main() {
go func() {
defer wg.Done()
rhl.Println("starting web-ctrl")
- StartControlWeb(*webAddr, conf, rddb.GetInterface(), sessions.GetInterface())
+ StartControlWeb(webAddr.Get().(string), conf, rddb.GetInterface(), sessions.GetInterface())
rhl.Println("web-ctrl finished")
}()
@@ -89,7 +115,7 @@ func main() {
go func() {
defer wg.Done()
rhl.Println("starting telnet-ctrl")
- StartControlTelnet(*telnetAddr, conf, rddb.GetInterface(), sessions.GetInterface())
+ StartControlTelnet(telnetAddr.Get().(string), conf, rddb.GetInterface(), sessions.GetInterface())
rhl.Println("telnet-ctrl finished")
}()