Skip to content

Commit

Permalink
👔 up: cflag - print error stack on debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Dec 3, 2024
1 parent f2ce64c commit eb4fc22
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 4 additions & 0 deletions cflag/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/gookit/color"
"github.com/gookit/goutil"
"github.com/gookit/goutil/cliutil"
"github.com/gookit/goutil/errorx"
"github.com/gookit/goutil/mathutil"
"github.com/gookit/goutil/strutil"
)
Expand Down Expand Up @@ -103,6 +104,9 @@ func (a *App) Run() {
err := a.RunWithArgs(os.Args[1:])
if err != nil {
cliutil.Errorln("ERROR:", err)
if Debug {
fmt.Println(errorx.Newf("(debug mode)RUNTIME ERROR: %v", err))
}
os.Exit(1)
}
}
Expand Down
9 changes: 5 additions & 4 deletions cflag/cflag.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ package cflag

import (
"flag"
"fmt"
"io"
"os"
"path/filepath"
Expand Down Expand Up @@ -233,10 +234,10 @@ func (c *CFlags) Parse(args []string) error {

defer func() {
if err := recover(); err != nil {
cliutil.Errorln("ERROR:", err)
if Debug {
cliutil.Errorln("recover error on run parse")
fmt.Println(errorx.Newf("(debug mode)RECOVERD PARSE ERROR: %v", err))
}
cliutil.Errorln("ERROR:", err)
}
}()

Expand Down Expand Up @@ -492,14 +493,14 @@ func (c *CFlags) renderOptionsHelp(buf *strutil.Buffer) {

// Boolean flags of one ASCII letter are so common we
// treat them specially, putting their usage on the same line.
if b.Len() <= 20 { // space, space, '-', 'x'.
if b.Len() <= 32 { // space, space, '-', 'x'.
b.WriteString("\t")
} else {
// Four spaces before the tab triggers good alignment
// for both 4- and 8-space tab stops.
b.WriteString("\n \t")
}
b.WriteString(strings.ReplaceAll(usage, "\n", "\n \t"))
b.WriteString(strings.ReplaceAll(usage, "\n", "\n \t"))

// put quotes on the string value
if isZero, isStr := IsZeroValue(opt, opt.DefValue); !isZero {
Expand Down

0 comments on commit eb4fc22

Please sign in to comment.