mirror of
https://github.com/vbatts/go-mtree.git
synced 2025-09-13 13:53:20 +00:00
gomtree: return exit status != 0 on error
This was broken during the refactor for "gomtree validate" in commit83c9fdb78b
("refactor: prefactor for adding new subcommands"), resulting in any code that relied on our exit code to silently treat all errors as non-fatal. Our tests did not catch this due to a quirky POSIX-ism with regards to "! cmd" and "set -e" which is fixed in a follow-up patch. Fixes:83c9fdb78b
("refactor: prefactor for adding new subcommands") Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
This commit is contained in:
parent
12e242c268
commit
23151ae80f
1 changed files with 8 additions and 12 deletions
|
@ -1,7 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
|
@ -51,23 +50,20 @@ to support xattrs and interacting with tar archives.`
|
|||
app.OnUsageError = func(ctx *cli.Context, err error, isSubcommand bool) error {
|
||||
if ctx.Command.Name == "gomtree" && strings.Contains(err.Error(), "flag provided but not defined") {
|
||||
runValidate = true
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
|
||||
// So we run the command again with the validate command as the default.
|
||||
if runValidate {
|
||||
err := app.Run(os.Args)
|
||||
// If it failed, run the command again with the validate command as the
|
||||
// default if it failed.
|
||||
if err != nil && runValidate {
|
||||
app.OnUsageError = nil
|
||||
args := []string{os.Args[0], "validate"}
|
||||
args = append(args, os.Args[1:]...)
|
||||
if err := app.Run(args); err != nil {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
err = app.Run(args)
|
||||
}
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue