Compare commits

..

1 Commits

Author SHA1 Message Date
4866cfd31c feat: Introduces a new help error
All checks were successful
continuous-integration/drone/pr Build is passing
2025-03-13 13:47:32 +01:00

View File

@ -3,6 +3,7 @@ package cli
import (
"fmt"
"os"
"strings"
"coopcloud.tech/abra/cli/app"
"coopcloud.tech/abra/cli/catalogue"
@ -40,7 +41,7 @@ func Run(version, commit string) {
}
for _, path := range paths {
if err := os.Mkdir(path, 0764); err != nil {
if err := os.Mkdir(path, 0o764); err != nil {
if !os.IsExist(err) {
log.Fatal(err)
}
@ -66,8 +67,9 @@ func Run(version, commit string) {
}
rootCmd.CompletionOptions.DisableDefaultCmd = true
// This prevents displaying usage for errors returned from RunE
// We handle errors ourself
rootCmd.SilenceUsage = true
rootCmd.SilenceErrors = true
manCommand := &cobra.Command{
Use: "man [flags]",
@ -214,7 +216,15 @@ func Run(version, commit string) {
app.AppEnvCommand,
)
if err := rootCmd.Execute(); err != nil {
if cmd, err := rootCmd.ExecuteC(); err != nil {
fmt.Printf("Error: %s\n", err)
if strings.HasPrefix(err.Error(), "unknown flag") {
fmt.Println()
cmd.Usage()
} else if !internal.Debug {
fmt.Println()
fmt.Printf("Run with --debug for more info.\n")
}
os.Exit(1)
}
}