@@ -62,18 +62,40 @@ func mustDelegateToMoby(ctxType string) bool {
62
62
63
63
// Exec delegates to com.docker.cli if on moby context
64
64
func Exec (root * cobra.Command ) {
65
+ childExit := make (chan bool )
66
+ err := RunDocker (childExit , os .Args [1 :]... )
67
+ childExit <- true
68
+ if err != nil {
69
+ metrics .Track (store .DefaultContextType , os .Args [1 :], metrics .FailureStatus )
70
+
71
+ if exiterr , ok := err .(* exec.ExitError ); ok {
72
+ os .Exit (exiterr .ExitCode ())
73
+ }
74
+ fmt .Fprintln (os .Stderr , err )
75
+ os .Exit (1 )
76
+ }
77
+ command := metrics .GetCommand (os .Args [1 :])
78
+ if command == "build" {
79
+ utils .DisplayScanSuggestMsg ()
80
+ }
81
+ metrics .Track (store .DefaultContextType , os .Args [1 :], metrics .SuccessStatus )
82
+
83
+ os .Exit (0 )
84
+ }
85
+
86
+ // RunDocker runs a docker command, and forward signals to the shellout command (stops listening to signals when an event is sent to childExit)
87
+ func RunDocker (childExit chan bool , args ... string ) error {
65
88
execBinary , err := resolvepath .LookPath (ComDockerCli )
66
89
if err != nil {
67
90
fmt .Fprintln (os .Stderr , err )
68
91
os .Exit (1 )
69
92
}
70
- cmd := exec .Command (execBinary , os . Args [ 1 :] ... )
93
+ cmd := exec .Command (execBinary , args ... )
71
94
cmd .Stdin = os .Stdin
72
95
cmd .Stdout = os .Stdout
73
96
cmd .Stderr = os .Stderr
74
97
75
98
signals := make (chan os.Signal , 1 )
76
- childExit := make (chan bool )
77
99
signal .Notify (signals ) // catch all signals
78
100
go func () {
79
101
for {
@@ -90,24 +112,7 @@ func Exec(root *cobra.Command) {
90
112
}
91
113
}()
92
114
93
- err = cmd .Run ()
94
- childExit <- true
95
- if err != nil {
96
- metrics .Track (store .DefaultContextType , os .Args [1 :], metrics .FailureStatus )
97
-
98
- if exiterr , ok := err .(* exec.ExitError ); ok {
99
- os .Exit (exiterr .ExitCode ())
100
- }
101
- fmt .Fprintln (os .Stderr , err )
102
- os .Exit (1 )
103
- }
104
- command := metrics .GetCommand (os .Args [1 :])
105
- if command == "build" {
106
- utils .DisplayScanSuggestMsg ()
107
- }
108
- metrics .Track (store .DefaultContextType , os .Args [1 :], metrics .SuccessStatus )
109
-
110
- os .Exit (0 )
115
+ return cmd .Run ()
111
116
}
112
117
113
118
// IsDefaultContextCommand checks if the command exists in the classic cli (issues a shellout --help)
0 commit comments