Commit 3bd81be6 authored by Sebastian Stark's avatar Sebastian Stark

handle flag.Parse() error value

  - if it is ErrHelp, return 0 and exit
  - before "snaprd subcmd -h" returned a non-zero value
parent f5586733
......@@ -127,7 +127,7 @@ func loadConfig() (*Config, error) {
switch subcmd {
case "run":
{
flags := flag.NewFlagSet(subcmd, flag.ExitOnError)
flags := flag.NewFlagSet(subcmd, flag.ContinueOnError)
flags.StringVar(&(config.RsyncPath),
"rsyncPath", "/usr/bin/rsync",
"path to rsync binary")
......@@ -168,7 +168,9 @@ func loadConfig() (*Config, error) {
"minGbSpace", 0,
"if set, keep at least x GiB of the snapshots filesystem free")
flags.Parse(os.Args[2:])
if err := flags.Parse(os.Args[2:]); err != nil {
return nil, err
}
if config.SchedFile != "" {
schedules.addFromFile(config.SchedFile)
}
......@@ -189,7 +191,7 @@ func loadConfig() (*Config, error) {
}
case "list":
{
flags := flag.NewFlagSet(subcmd, flag.ExitOnError)
flags := flag.NewFlagSet(subcmd, flag.ContinueOnError)
flags.StringVar(&(config.repository),
"repository", defaultRepository,
"where snapshots are located")
......@@ -208,7 +210,10 @@ func loadConfig() (*Config, error) {
flags.StringVar(&(config.SchedFile),
"schedFile", defaultSchedFileName,
"path to external schedules")
flags.Parse(os.Args[2:])
if err := flags.Parse(os.Args[2:]); err != nil {
return nil, err
}
if config.SchedFile != "" {
schedules.addFromFile(config.SchedFile)
}
......@@ -226,11 +231,14 @@ func loadConfig() (*Config, error) {
}
case "scheds":
{
flags := flag.NewFlagSet(subcmd, flag.ExitOnError)
flags := flag.NewFlagSet(subcmd, flag.ContinueOnError)
flags.StringVar(&(config.SchedFile),
"schedFile", defaultSchedFileName,
"path to external schedules")
flags.Parse(os.Args[2:])
if err := flags.Parse(os.Args[2:]); err != nil {
return nil, err
}
if config.SchedFile != "" {
schedules.addFromFile(config.SchedFile)
}
......
......@@ -7,6 +7,7 @@ package main
import (
"errors"
"flag"
"fmt"
"log"
"os"
......@@ -241,6 +242,9 @@ func mainExitCode() int {
logger = log.New(os.Stderr, "", log.Ldate|log.Ltime|log.Lshortfile)
var err error
if config, err = loadConfig(); err != nil || config == nil {
if err == flag.ErrHelp {
return 0
}
log.Println(err)
return 1
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment