Fix flag parsing after the configuration file

Fixes #52
pull/51/head
Mariano Cano 5 years ago
parent 8a05cdde52
commit 6592c4784b

@ -2,6 +2,7 @@ package main
import (
"bytes"
"flag"
"fmt"
"io/ioutil"
"log"
@ -143,6 +144,25 @@ intermediate private key.`,
}
app.Action = func(ctx *cli.Context) error {
// Hack to be able to run a the top action as a subcommand
cmd := cli.Command{Name: "start", Action: startAction, Flags: app.Flags}
set := flag.NewFlagSet(app.Name, flag.ContinueOnError)
set.Parse(os.Args)
ctx = cli.NewContext(app, set, nil)
return cmd.Run(ctx)
}
if err := app.Run(os.Args); err != nil {
if os.Getenv("STEPDEBUG") == "1" {
fmt.Fprintf(os.Stderr, "%+v\n", err)
} else {
fmt.Fprintln(os.Stderr, err)
}
os.Exit(1)
}
}
func startAction(ctx *cli.Context) error {
passFile := ctx.String("password-file")
// If zero cmd line args show help, if >1 cmd line args show error.
@ -177,16 +197,6 @@ intermediate private key.`,
fatal(err)
}
return nil
}
if err := app.Run(os.Args); err != nil {
if os.Getenv("STEPDEBUG") == "1" {
fmt.Fprintf(os.Stderr, "%+v\n", err)
} else {
fmt.Fprintln(os.Stderr, err)
}
os.Exit(1)
}
}
// fatal writes the passed error on the standard error and exits with the exit

Loading…
Cancel
Save