Skip to content

Commit

Permalink
fix: correctly assign 'verbose' and 'debug' variables
Browse files Browse the repository at this point in the history
We derefered to the value too early. We only get the correct value after parsing it.
  • Loading branch information
d-Rickyy-b committed Jan 3, 2021
1 parent 66a80a6 commit cd11006
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ func main() {
parser := argparse.NewParser("backmeup", "The lightweight backup tool for the CLI")
parser.ExitOnHelp(true)
configPath := parser.String("c", "config", &argparse.Options{Required: true, Help: "Path to the config.yml file", Default: "config.yml"})
VERBOSE = *parser.Flag("v", "verbose", &argparse.Options{Required: false, Help: "Enable verbose logging", Default: false})
DEBUG = *parser.Flag("d", "debug", &argparse.Options{Required: false, Help: "Enable debug logging", Default: false})
verbose := parser.Flag("v", "verbose", &argparse.Options{Required: false, Help: "Enable verbose logging", Default: false})
debug := parser.Flag("d", "debug", &argparse.Options{Required: false, Help: "Enable debug logging", Default: false})

if err := parser.Parse(os.Args); err != nil {
// In case of error print error and print usage
Expand All @@ -217,6 +217,10 @@ func main() {
os.Exit(1)
}

// We didn't get the true values of the arguments before calling parser.Parse()
VERBOSE = *verbose
DEBUG = *debug

conf, err := config.ReadConfig(*configPath)
if err != nil {
log.Println("Error while parsing yaml config!")
Expand Down

0 comments on commit cd11006

Please # to comment.