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 {
|
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"
|
"os/exec"
|
||||||
)
|
)
|
||||||
|
|
||||||
func bashShell(cluster string) error {
|
func bashShell(cluster string, command string) error {
|
||||||
kubeConfigPath, err := getKubeConfig(cluster)
|
kubeConfigPath, err := getKubeConfig(cluster)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -19,6 +19,11 @@ func bashShell(cluster string) error {
|
|||||||
|
|
||||||
cmd := exec.Command(bashPath, "--noprofile", "--norc")
|
cmd := exec.Command(bashPath, "--noprofile", "--norc")
|
||||||
|
|
||||||
|
if len(command) > 0 {
|
||||||
|
cmd.Args = append(cmd.Args, "-c", command)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Set up stdio
|
// Set up stdio
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stdin = os.Stdin
|
cmd.Stdin = os.Stdin
|
||||||
|
4
main.go
4
main.go
@ -55,6 +55,10 @@ func main() {
|
|||||||
Value: defaultK3sClusterName,
|
Value: defaultK3sClusterName,
|
||||||
Usage: "Set a name for the cluster",
|
Usage: "Set a name for the cluster",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "command, c",
|
||||||
|
Usage: "Run a shell command in the context of the cluster",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Action: run.Bash,
|
Action: run.Bash,
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user