mirror of
https://github.com/vbatts/go-mtree.git
synced 2025-09-13 22:03:19 +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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -51,23 +50,20 @@ to support xattrs and interacting with tar archives.`
|
||||||
app.OnUsageError = func(ctx *cli.Context, err error, isSubcommand bool) error {
|
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") {
|
if ctx.Command.Name == "gomtree" && strings.Contains(err.Error(), "flag provided but not defined") {
|
||||||
runValidate = true
|
runValidate = true
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := app.Run(os.Args); err != nil {
|
err := app.Run(os.Args)
|
||||||
fmt.Println(err.Error())
|
// If it failed, run the command again with the validate command as the
|
||||||
}
|
// default if it failed.
|
||||||
|
if err != nil && runValidate {
|
||||||
// So we run the command again with the validate command as the default.
|
|
||||||
if runValidate {
|
|
||||||
app.OnUsageError = nil
|
app.OnUsageError = nil
|
||||||
args := []string{os.Args[0], "validate"}
|
args := []string{os.Args[0], "validate"}
|
||||||
args = append(args, os.Args[1:]...)
|
args = append(args, os.Args[1:]...)
|
||||||
if err := app.Run(args); err != nil {
|
err = app.Run(args)
|
||||||
fmt.Println(err.Error())
|
}
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue