fortify: handle errors via MustParse
The errSuccess behaviour is kept for beforeExit. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
parent
ba1498cd18
commit
478b27922c
32
main.go
32
main.go
@ -53,30 +53,14 @@ func main() {
|
|||||||
log.Fatal("this program must not run as root")
|
log.Fatal("this program must not run as root")
|
||||||
}
|
}
|
||||||
|
|
||||||
err := buildCommand(os.Stderr).Parse(os.Args[1:])
|
buildCommand(os.Stderr).MustParse(os.Args[1:], func(err error) {
|
||||||
if errors.Is(err, errSuccess) || errors.Is(err, command.ErrHelp) {
|
fmsg.Verbosef("command returned %v", err)
|
||||||
internal.Exit(0)
|
if errors.Is(err, errSuccess) {
|
||||||
panic("unreachable")
|
fmsg.BeforeExit()
|
||||||
}
|
os.Exit(0)
|
||||||
if errors.Is(err, command.ErrNoMatch) || errors.Is(err, command.ErrEmptyTree) {
|
}
|
||||||
internal.Exit(1)
|
})
|
||||||
panic("unreachable")
|
log.Fatal("unreachable")
|
||||||
}
|
|
||||||
if err == nil {
|
|
||||||
log.Fatal("unreachable")
|
|
||||||
}
|
|
||||||
|
|
||||||
var flagError command.FlagError
|
|
||||||
if !errors.As(err, &flagError) {
|
|
||||||
log.Printf("command: %v", err)
|
|
||||||
internal.Exit(1)
|
|
||||||
panic("unreachable")
|
|
||||||
}
|
|
||||||
fmsg.Verbose(flagError.Error())
|
|
||||||
if flagError.Success() {
|
|
||||||
internal.Exit(0)
|
|
||||||
}
|
|
||||||
internal.Exit(1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildCommand(out io.Writer) command.Command {
|
func buildCommand(out io.Writer) command.Command {
|
||||||
|
Loading…
Reference in New Issue
Block a user