mirror of
https://github.com/kovidgoyal/kitty.git
synced 2024-09-20 02:57:19 +03:00
Better error message for kitty shell when running unknown command
This commit is contained in:
parent
a4e43b3925
commit
bdd04f37d6
@ -113,7 +113,7 @@ func show_basic_help() {
|
|||||||
cli.ShowHelpInPager(output.String())
|
cli.ShowHelpInPager(output.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func exec_command(rl *readline.Readline, cmdline string) bool {
|
func exec_command(at_root_command *cli.Command, rl *readline.Readline, cmdline string) bool {
|
||||||
parsed_cmdline, err := shlex.Split(cmdline)
|
parsed_cmdline, err := shlex.Split(cmdline)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, "Could not parse cmdline:", err)
|
fmt.Fprintln(os.Stderr, "Could not parse cmdline:", err)
|
||||||
@ -142,17 +142,21 @@ func exec_command(rl *readline.Readline, cmdline string) bool {
|
|||||||
case "help":
|
case "help":
|
||||||
fmt.Println("Show help")
|
fmt.Println("Show help")
|
||||||
default:
|
default:
|
||||||
r := EntryPoint(cli.NewRootCommand())
|
sc := at_root_command.FindSubCommand(parsed_cmdline[1])
|
||||||
sc := r.FindSubCommand(parsed_cmdline[1])
|
|
||||||
if sc == nil {
|
if sc == nil {
|
||||||
hi.ExitCode = 1
|
hi.ExitCode = 1
|
||||||
fmt.Fprintln(os.Stderr, "No command named", formatter.BrightRed(parsed_cmdline[1]), ". Type help for a list of commands")
|
fmt.Fprintln(os.Stderr, "No command named", formatter.BrightRed(parsed_cmdline[1])+". Type help for a list of commands")
|
||||||
} else {
|
} else {
|
||||||
sc.ShowHelpWithCommandString(sc.Name)
|
sc.ShowHelpWithCommandString(sc.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
default:
|
default:
|
||||||
|
if at_root_command.FindSubCommand(parsed_cmdline[0]) == nil {
|
||||||
|
hi.ExitCode = 1
|
||||||
|
fmt.Fprintln(os.Stderr, "No command named", formatter.BrightRed(parsed_cmdline[0])+". Type help for a list of commands")
|
||||||
|
return true
|
||||||
|
}
|
||||||
exe, err := os.Executable()
|
exe, err := os.Executable()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
exe, err = exec.LookPath("kitty-tool")
|
exe, err = exec.LookPath("kitty-tool")
|
||||||
@ -217,7 +221,7 @@ func shell_main(cmd *cli.Command, args []string) (int, error) {
|
|||||||
if err == ErrExec {
|
if err == ErrExec {
|
||||||
cmdline := rl.AllText()
|
cmdline := rl.AllText()
|
||||||
cmdline = strings.ReplaceAll(cmdline, "\\\n", "")
|
cmdline = strings.ReplaceAll(cmdline, "\\\n", "")
|
||||||
if !exec_command(rl, cmdline) {
|
if !exec_command(cmd, rl, cmdline) {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
|
Loading…
Reference in New Issue
Block a user