Add the ability to execute commands directly with the bash subcommand
In addition to provide an interactive shell, this patch adds the '--command' and '-c' options to allow user to issue a command in the context of a cluster. For example: $ k3d bash -c 'kubectl cluster-info'
This commit is contained in:
parent
5c6f2d7dc5
commit
2971dd6845
@ -355,5 +355,5 @@ func GetKubeConfig(c *cli.Context) error {
|
||||
}
|
||||
|
||||
func Bash(c *cli.Context) error {
|
||||
return bashShell(c.String("name"))
|
||||
return bashShell(c.String("name"), c.String("command"))
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
func bashShell(cluster string) error {
|
||||
func bashShell(cluster string, command string) error {
|
||||
kubeConfigPath, err := getKubeConfig(cluster)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -19,6 +19,11 @@ func bashShell(cluster string) error {
|
||||
|
||||
cmd := exec.Command(bashPath, "--noprofile", "--norc")
|
||||
|
||||
if len(command) > 0 {
|
||||
cmd.Args = append(cmd.Args, "-c", command)
|
||||
|
||||
}
|
||||
|
||||
// Set up stdio
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stdin = os.Stdin
|
||||
|
Loading…
Reference in New Issue
Block a user