1
0

Make the config file a required argument

When running in a container we should not attempt to look in the
homedir for a config file. The user should explicitly mount it into the
container and pass it to the program.
This commit is contained in:
Tony Grosinger 2022-12-06 08:38:17 -08:00
parent 1446d3c942
commit 9ba150953e
4 changed files with 3 additions and 16 deletions

View File

@ -77,7 +77,7 @@ The `ipv4CheckUrl` and `ipv6CheckUrl` configuration settings are optional. If se
./digitalocean-dynamic-ip
```
Optionally, you can create the configuration file with any name wherever you want, and pass it as a command line argument:
Configuration file location must be specified as a positional argument:
```bash
#run:

View File

@ -13,8 +13,6 @@ import (
"net/url"
"os"
"strconv"
homedir "github.com/mitchellh/go-homedir"
)
func checkError(err error) {
@ -117,16 +115,11 @@ func GetConfig() ClientConfig {
log.SetOutput(os.Stdout)
}
configFile := ""
if len(flag.Args()) == 0 {
var err error
configFile, err = homedir.Dir()
checkError(err)
configFile += "/.digitalocean-dynamic-ip.json"
} else {
configFile = flag.Args()[0]
logError("Missing required argument with config file path.")
}
configFile := flag.Args()[0]
log.Printf("Using Config file: %s", configFile)
getfile, err := ioutil.ReadFile(configFile)
@ -142,8 +135,6 @@ func usage() {
"-h | -help\n\tShow this help message\n"+
"-d | -debug\n\tPrint debug messages to standard output\n"+
"[config_file]\n\tlocation of the configuration file\n\n"+
"If the [config_file] parameter is not passed, then the default\n"+
"config location of ~/.digitalocean-dynamic-ip.json will be used.\n\n"+
"example usages:\n\t%[1]s -help\n"+
"\t%[1]s\n"+
"\t%[1]s %[2]s\n"+

2
go.mod
View File

@ -1,5 +1,3 @@
module github.com/anaganisk/digitalocean-dynamic-dns-ip
require github.com/mitchellh/go-homedir v1.1.0
go 1.8

2
go.sum
View File

@ -1,2 +0,0 @@
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=