@@ -34,6 +34,7 @@ var debugCmd = &cobra.Command{
3434 Example : `
3535debug-ctr debug --target=my-distroless
3636debug-ctr debug --image=busybox:1.28 --target=my-distroless
37+ debug-ctr debug --image=busybox:1.28 --target=my-distroless --open-term
3738debug-ctr debug --image=docker.io/alpine:latest --target=my-distroless --copy-to=my-distroless-copy
3839debug-ctr debug --image=docker.io/alpine:latest --target=my-distroless --copy-to=my-distroless-copy --entrypoint="/.debugger/sleep" --cmd="365d"
3940` ,
@@ -43,6 +44,7 @@ debug-ctr debug --image=docker.io/alpine:latest --target=my-distroless --copy-to
4344 return err
4445 },
4546 RunE : func (cmd * cobra.Command , args []string ) error {
47+ openTerm , _ := cmd .PersistentFlags ().GetBool ("open-term" )
4648 debugImage , _ := cmd .PersistentFlags ().GetString ("image" )
4749 targetContainer , _ := cmd .PersistentFlags ().GetString ("target" )
4850 copyContainerName , _ := cmd .PersistentFlags ().GetString ("copy-to" )
@@ -81,12 +83,13 @@ debug-ctr debug --image=docker.io/alpine:latest --target=my-distroless --copy-to
8183 log .Printf ("$ %s" , dockerExecCmd )
8284 log .Println ("-------------------------------" )
8385
84- switch runtime .GOOS {
85- //TODO: windows
86- //TODO: linux
87- case "darwin" :
86+ if openTerm {
87+ switch runtime .GOOS {
88+ //TODO: windows
89+ //TODO: linux
90+ case "darwin" :
8891
89- args := fmt .Sprintf (`
92+ args := fmt .Sprintf (`
9093 reopen
9194 tell current window
9295 create tab with default profile
@@ -96,9 +99,10 @@ debug-ctr debug --image=docker.io/alpine:latest --target=my-distroless --copy-to
9699 end tell
97100 end tell` , strings .ReplaceAll (strings .ReplaceAll (dockerExecCmd , `\` , `\\` ), `"` , `\"` ))
98101
99- err := exec .Command ("/usr/bin/osascript" , "-e" , "tell application \" iTerm\" " , "-e" , args ).Run ()
100- if err != nil {
101- log .Fatal (err )
102+ err := exec .Command ("/usr/bin/osascript" , "-e" , "tell application \" iTerm\" " , "-e" , args ).Run ()
103+ if err != nil {
104+ log .Fatal (err )
105+ }
102106 }
103107 }
104108
@@ -109,6 +113,7 @@ debug-ctr debug --image=docker.io/alpine:latest --target=my-distroless --copy-to
109113func init () {
110114 rootCmd .AddCommand (debugCmd )
111115
116+ debugCmd .PersistentFlags ().Bool ("open-term" , false , "(optional) Open a host terminal to shell into the container automatically" )
112117 debugCmd .PersistentFlags ().String ("image" , "docker.io/library/busybox:latest" , "(optional) The image to use for debugging purposes" )
113118 debugCmd .PersistentFlags ().String ("target" , "" , "(required) The target container to debug" )
114119 debugCmd .PersistentFlags ().String ("copy-to" , "" , "(optional) The name of the copy container" )
0 commit comments