print error messages from run using new printer
This commit is contained in:
parent
fa9f33a5de
commit
ba7c3ac52d
2 changed files with 18 additions and 5 deletions
|
@ -23,7 +23,6 @@ var (
|
|||
|
||||
func main() {
|
||||
if err := run(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "ERROR: %v.\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
@ -181,13 +180,18 @@ func run() error {
|
|||
|
||||
exe, ok := executorMap[command]
|
||||
if !ok {
|
||||
err := executor.UnknownCommandError{Command: command}
|
||||
|
||||
printer.PrintFailure(err.Error() + ".")
|
||||
flag.Usage()
|
||||
|
||||
return executor.UnknownCommandError{Command: command}
|
||||
return err
|
||||
}
|
||||
|
||||
if err := executor.Execute(exe, args); err != nil {
|
||||
return fmt.Errorf("(%s) %w", command, err)
|
||||
printer.PrintFailure("(" + command + ") " + err.Error() + ".")
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -23,6 +23,8 @@ type theme struct {
|
|||
green string
|
||||
boldgreen string
|
||||
grey string
|
||||
red string
|
||||
boldred string
|
||||
}
|
||||
|
||||
type Printer struct {
|
||||
|
@ -51,6 +53,8 @@ func NewPrinter(
|
|||
green: "\033[32m",
|
||||
boldgreen: "\033[32;1m",
|
||||
grey: "\033[90m",
|
||||
red: "\033[31m",
|
||||
boldred: "\033[31;1m",
|
||||
}
|
||||
|
||||
if maxTerminalWidth < minTerminalWidth {
|
||||
|
@ -73,7 +77,7 @@ func NewPrinter(
|
|||
}
|
||||
|
||||
func (p Printer) PrintSuccess(text string) {
|
||||
success := p.theme.green + p.successSymbol + p.theme.reset
|
||||
success := p.theme.boldgreen + p.successSymbol + p.theme.reset
|
||||
if p.noColor {
|
||||
success = p.successSymbol
|
||||
}
|
||||
|
@ -82,7 +86,12 @@ func (p Printer) PrintSuccess(text string) {
|
|||
}
|
||||
|
||||
func (p Printer) PrintFailure(text string) {
|
||||
printToStderr(p.failureSymbol + " " + text)
|
||||
failure := p.theme.boldred + p.failureSymbol + p.theme.reset
|
||||
if p.noColor {
|
||||
failure = p.failureSymbol
|
||||
}
|
||||
|
||||
printToStderr(failure + " " + text + "\n")
|
||||
}
|
||||
|
||||
func (p Printer) PrintInfo(text string) {
|
||||
|
|
Loading…
Reference in a new issue