/
shell.go
39 lines (32 loc) · 887 Bytes
/
shell.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
package logic
import (
"github.com/spf13/cobra"
"github.com/rewardenv/reward/internal/shell"
"github.com/rewardenv/reward/pkg/util"
)
// RunCmdShell opens a shell in the environment's default application container.
func (c *Client) RunCmdShell(cmd *cobra.Command, args []string) error {
c.SetShellContainer(c.EnvType())
c.SetDefaultShellCommand(c.ShellContainer)
c.SetShellUser(c.ShellContainer)
var shellCommand []string
if len(args) > 0 {
shellCommand = util.ExtractUnknownArgs(cmd.Flags(), args)
} else {
shellCommand = util.ExtractUnknownArgs(cmd.Flags(), []string{c.DefaultShellCommand})
}
passedArgs := append([]string{
"exec",
"--user",
c.ShellUser,
c.ShellContainer,
}, shellCommand...)
err := c.RunCmdEnvDockerCompose(passedArgs,
shell.WithCatchOutput(false),
shell.WithSuppressOutput(true),
)
if err != nil {
return err
}
return nil
}