/
wrap.go
56 lines (43 loc) · 933 Bytes
/
wrap.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
47
48
49
50
51
52
53
54
55
56
package cmd
import (
"os"
"github.com/get-bridge/truss-cli/truss"
"github.com/spf13/cobra"
)
// wrapCmd represents the wrap command
var wrapCmd = &cobra.Command{
Use: "wrap",
Long: `
Sets KUBECONFIG and then executes the subcommand:
$ truss wrap -e edge-cmh -- printenv
This allows you to do this:
$ truss wrap -e edge-cmh -- k9s
`,
Short: "Wraps a subcommand with truss environment variables",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
cmd.Help()
os.Exit(0)
}
bin := args[0]
binargs := args[1:]
kubeconfig, err := getKubeconfig()
if err != nil {
return err
}
input := &truss.WrapInput{
Kubeconfig: kubeconfig,
Stdout: cmd.OutOrStdout(),
Stdin: os.Stdin,
Stderr: cmd.ErrOrStderr(),
}
err = truss.Wrap(input, bin, binargs...)
if err != nil {
return err
}
return nil
},
}
func init() {
rootCmd.AddCommand(wrapCmd)
}