mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-06 01:05:48 +02:00
kittens: Fix errors not being reported to user when run a UI kitten
Fixes #6403
This commit is contained in:
@@ -39,6 +39,8 @@ type Command struct {
|
|||||||
IgnoreAllArgs bool
|
IgnoreAllArgs bool
|
||||||
// Specialised arg parsing
|
// Specialised arg parsing
|
||||||
ParseArgsForCompletion func(cmd *Command, args []string, completions *Completions)
|
ParseArgsForCompletion func(cmd *Command, args []string, completions *Completions)
|
||||||
|
// Callback that is called on error
|
||||||
|
CallbackOnError func(cmd *Command, err error, during_parsing bool, exit_code int) (final_exit_code int)
|
||||||
|
|
||||||
SubCommandGroups []*CommandGroup
|
SubCommandGroups []*CommandGroup
|
||||||
OptionGroups []*OptionGroup
|
OptionGroups []*OptionGroup
|
||||||
@@ -529,6 +531,9 @@ func (self *Command) ExecArgs(args []string) (exit_code int) {
|
|||||||
}
|
}
|
||||||
cmd, err := root.ParseArgs(args)
|
cmd, err := root.ParseArgs(args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if self.CallbackOnError != nil {
|
||||||
|
return self.CallbackOnError(cmd, err, true, 1)
|
||||||
|
}
|
||||||
ShowError(err)
|
ShowError(err)
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
@@ -543,10 +548,13 @@ func (self *Command) ExecArgs(args []string) (exit_code int) {
|
|||||||
} else if cmd.Run != nil {
|
} else if cmd.Run != nil {
|
||||||
exit_code, err = cmd.Run(cmd, cmd.Args)
|
exit_code, err = cmd.Run(cmd, cmd.Args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ShowError(err)
|
|
||||||
if exit_code == 0 {
|
if exit_code == 0 {
|
||||||
exit_code = 1
|
exit_code = 1
|
||||||
}
|
}
|
||||||
|
if self.CallbackOnError != nil {
|
||||||
|
return self.CallbackOnError(cmd, err, false, exit_code)
|
||||||
|
}
|
||||||
|
ShowError(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ var _ = fmt.Print
|
|||||||
func KittyToolEntryPoints(root *cli.Command) {
|
func KittyToolEntryPoints(root *cli.Command) {
|
||||||
root.Add(cli.OptionSpec{
|
root.Add(cli.OptionSpec{
|
||||||
Name: "--version", Type: "bool-set", Help: "The current kitten version."})
|
Name: "--version", Type: "bool-set", Help: "The current kitten version."})
|
||||||
|
tui.PrepareRootCmd(root)
|
||||||
// @
|
// @
|
||||||
at.EntryPoint(root)
|
at.EntryPoint(root)
|
||||||
// update-self
|
// update-self
|
||||||
|
|||||||
@@ -15,9 +15,22 @@ import (
|
|||||||
|
|
||||||
var _ = fmt.Print
|
var _ = fmt.Print
|
||||||
|
|
||||||
|
var RunningAsUI = utils.Once(func() bool {
|
||||||
|
defer func() { os.Unsetenv("KITTEN_RUNNING_AS_UI") }()
|
||||||
|
return os.Getenv("KITTEN_RUNNING_AS_UI") != ""
|
||||||
|
})
|
||||||
|
|
||||||
|
func PrepareRootCmd(root *cli.Command) {
|
||||||
|
if RunningAsUI() {
|
||||||
|
root.CallbackOnError = func(cmd *cli.Command, err error, during_parsing bool, exit_code int) int {
|
||||||
|
ReportError(err)
|
||||||
|
return exit_code
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func KittenOutputSerializer() func(any) (string, error) {
|
func KittenOutputSerializer() func(any) (string, error) {
|
||||||
write_with_escape_code := os.Getenv("KITTEN_RUNNING_AS_UI") != ""
|
write_with_escape_code := RunningAsUI()
|
||||||
os.Unsetenv("KITTEN_RUNNING_AS_UI")
|
|
||||||
if write_with_escape_code {
|
if write_with_escape_code {
|
||||||
return func(what any) (string, error) {
|
return func(what any) (string, error) {
|
||||||
data, err := json.Marshal(what)
|
data, err := json.Marshal(what)
|
||||||
|
|||||||
Reference in New Issue
Block a user