/
command.go
46 lines (39 loc) · 1.02 KB
/
command.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package cmd
import (
"context"
"os"
"github.com/loft-sh/devpod-provider-kubernetes/pkg/kubernetes"
"github.com/loft-sh/devpod-provider-kubernetes/pkg/options"
"github.com/loft-sh/log"
"github.com/spf13/cobra"
)
// CommandCmd holds the cmd flags
type CommandCmd struct{}
// NewCommandCmd defines a command
func NewCommandCmd() *cobra.Command {
cmd := &CommandCmd{}
commandCmd := &cobra.Command{
Use: "command",
Short: "Command a container",
RunE: func(_ *cobra.Command, args []string) error {
options, err := options.FromEnv()
if err != nil {
return err
}
return cmd.Run(context.Background(), options, log.Default.ErrorStreamOnly())
},
}
return commandCmd
}
// Run runs the command logic
func (cmd *CommandCmd) Run(ctx context.Context, options *options.Options, log log.Logger) error {
return kubernetes.NewKubernetesDriver(options, log).CommandDevContainer(
ctx,
options.DevContainerID,
os.Getenv("DEVCONTAINER_USER"),
os.Getenv("DEVCONTAINER_COMMAND"),
os.Stdin,
os.Stdout,
os.Stderr,
)
}