Created
December 31, 2017 15:27
-
-
Save Zhann/77686d4e07f9dae8cd851944e6fee648 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"os" | |
"os/exec" | |
"strings" | |
"github.com/mkideal/cli" | |
) | |
type argT struct { | |
cli.Helper | |
Kubectl string `cli:"kubectl" usage:"kubectl command args" prompt:"kubectl> "` | |
} | |
// KubeSh starts a very simple kubectl-shell so you don't have to keep typing kubectl | |
func KubeSh() { | |
for { | |
cli.Run(new(argT), func(ctx *cli.Context) error { | |
argv := ctx.Argv().(*argT) | |
cmd := exec.Command( | |
"kubectl", | |
strings.Fields(argv.Kubectl)..., | |
) | |
cmd.Stdin = os.Stdin | |
cmd.Stdout = os.Stdout | |
cmd.Stderr = os.Stderr | |
err := cmd.Run() | |
if err != nil { | |
fmt.Fprint(os.Stderr, err.Error()) | |
} | |
return nil | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment