Allow setting info message on command execution
parent
b544852ec7
commit
7d56789a20
|
|
@ -129,7 +129,7 @@ func execCmd(r Runner, bin string, bg bool, args ...string) ui.ActionHandler {
|
|||
return nil
|
||||
}
|
||||
}
|
||||
if run(true, r.App(), bin, bg, aa...) {
|
||||
if run(true, r.App(), bin, bg, "", aa...) {
|
||||
r.App().Flash().Info("Plugin command launched successfully!")
|
||||
} else {
|
||||
r.App().Flash().Info("Plugin command failed!")
|
||||
|
|
|
|||
|
|
@ -292,7 +292,7 @@ func (b *Browser) editCmd(evt *tcell.EventKey) *tcell.EventKey {
|
|||
if cfg := b.app.Conn().Config().Flags().KubeConfig; cfg != nil && *cfg != "" {
|
||||
args = append(args, "--kubeconfig", *cfg)
|
||||
}
|
||||
if !runK(true, b.app, append(args, n)...) {
|
||||
if !runK(true, b.app, "", append(args, n)...) {
|
||||
b.app.Flash().Err(errors.New("Edit exec failed"))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,22 +13,22 @@ import (
|
|||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func runK(clear bool, app *App, args ...string) bool {
|
||||
func runK(clear bool, app *App, info string, args ...string) bool {
|
||||
bin, err := exec.LookPath("kubectl")
|
||||
if err != nil {
|
||||
log.Error().Msgf("Unable to find kubectl command in path %v", err)
|
||||
return false
|
||||
}
|
||||
|
||||
return run(clear, app, bin, false, args...)
|
||||
return run(clear, app, bin, false, info, args...)
|
||||
}
|
||||
|
||||
func run(clear bool, app *App, bin string, bg bool, args ...string) bool {
|
||||
func run(clear bool, app *App, bin string, bg bool, info string, args ...string) bool {
|
||||
app.Halt()
|
||||
defer app.Resume()
|
||||
|
||||
return app.Suspend(func() {
|
||||
if err := execute(clear, bin, bg, args...); err != nil {
|
||||
if err := execute(clear, bin, bg, info, args...); err != nil {
|
||||
app.Flash().Errf("Command exited: %v", err)
|
||||
}
|
||||
})
|
||||
|
|
@ -41,10 +41,10 @@ func edit(clear bool, app *App, args ...string) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
return run(clear, app, bin, false, args...)
|
||||
return run(clear, app, bin, false, "", args...)
|
||||
}
|
||||
|
||||
func execute(clear bool, bin string, bg bool, args ...string) error {
|
||||
func execute(clear bool, bin string, bg bool, info string, args ...string) error {
|
||||
if clear {
|
||||
clearScreen()
|
||||
}
|
||||
|
|
@ -71,6 +71,8 @@ func execute(clear bool, bin string, bg bool, args ...string) error {
|
|||
err = cmd.Start()
|
||||
} else {
|
||||
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
|
||||
|
||||
_, _ = cmd.Stdout.Write([]byte(info))
|
||||
err = cmd.Run()
|
||||
}
|
||||
log.Debug().Msgf("Command returned error?? %v", err)
|
||||
|
|
|
|||
|
|
@ -176,7 +176,8 @@ func fetchContainers(f *watch.Factory, path string, includeInit bool) ([]string,
|
|||
func shellIn(a *App, path, co string) {
|
||||
args := computeShellArgs(path, co, a.Config.K9s.CurrentContext, a.Conn().Config().Flags().KubeConfig)
|
||||
log.Debug().Msgf("Shell args %v", args)
|
||||
if !runK(true, a, args...) {
|
||||
|
||||
if !runK(true, a, "", args...) {
|
||||
a.Flash().Err(errors.New("Shell exec failed"))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -345,7 +345,7 @@ func (x *Xray) editCmd(evt *tcell.EventKey) *tcell.EventKey {
|
|||
if cfg := x.app.Conn().Config().Flags().KubeConfig; cfg != nil && *cfg != "" {
|
||||
args = append(args, "--kubeconfig", *cfg)
|
||||
}
|
||||
if !runK(true, x.app, append(args, n)...) {
|
||||
if !runK(true, x.app, "", append(args, n)...) {
|
||||
x.app.Flash().Err(errors.New("Edit exec failed"))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue