Skip to content

Commit f4fcce9

Browse files
committed
feat: provide simple Fatal func
1 parent 18d1e5a commit f4fcce9

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

cli.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,13 @@ func GetAllSeq[T any](c *Command, id string) iter.Seq[T] {
239239
}
240240
}
241241

242+
// Fatal logs the given value to Stderr prefixed by "error: "
243+
// and then exits the program with the given code.
244+
func Fatal(code int, v any) {
245+
fmt.Fprintf(os.Stderr, "error: %v\n", v)
246+
os.Exit(code)
247+
}
248+
242249
// ParseOrExit will parse input based on this CommandInfo. If help was requested, it
243250
// will print the help message and exit the program successfully (status code 0). If
244251
// there is any other error, it will print the error and exit the program with failure
@@ -254,8 +261,7 @@ func (in CommandInfo) ParseTheseOrExit(args ...string) *Command {
254261
fmt.Print(e.HelpMsg)
255262
os.Exit(0)
256263
} else {
257-
fmt.Fprintf(os.Stderr, "error: %v\n", err)
258-
os.Exit(1)
264+
Fatal(1, err)
259265
}
260266
}
261267
return c

0 commit comments

Comments
 (0)