Add command-line option to set working directory

Signed-off-by: W. Michael Petullo <mike@flyn.org>
pull/3065/head
W. Michael Petullo 2024-01-03 11:40:45 -06:00
parent 8e79294413
commit 84d8e8f622
1 changed files with 7 additions and 1 deletions

View File

@ -51,6 +51,7 @@ const (
) )
var ( var (
wd = kingpin.Flag("working-directory", "Working directory for service.").Default(".").String()
configPath = kingpin.Flag("config", "Location of config.json.").Default("./config.json").String() configPath = kingpin.Flag("config", "Location of config.json.").Default("./config.json").String()
disableMailer = kingpin.Flag("disable-mailer", "Disable the mailer (for use with multi-system deployments)").Bool() disableMailer = kingpin.Flag("disable-mailer", "Disable the mailer (for use with multi-system deployments)").Bool()
mode = kingpin.Flag("mode", fmt.Sprintf("Run the binary in one of the modes (%s, %s or %s)", modeAll, modeAdmin, modePhish)). mode = kingpin.Flag("mode", fmt.Sprintf("Run the binary in one of the modes (%s, %s or %s)", modeAll, modeAdmin, modePhish)).
@ -66,10 +67,15 @@ func main() {
} }
kingpin.Version(string(version)) kingpin.Version(string(version))
// Parse the CLI flags and load the config // Parse the CLI flags, set working directory, and load the config
kingpin.CommandLine.HelpFlag.Short('h') kingpin.CommandLine.HelpFlag.Short('h')
kingpin.Parse() kingpin.Parse()
err := os.Chdir(*wd)
if err != nil {
log.Fatal(err)
}
// Load the config // Load the config
conf, err := config.LoadConfig(*configPath) conf, err := config.LoadConfig(*configPath)
// Just warn if a contact address hasn't been configured // Just warn if a contact address hasn't been configured