@@ -58,6 +58,11 @@ func main() {
5858 Name : "google-project" ,
5959 Usage : "the google cloud project for secrets without a project prefix" ,
6060 },
61+ & cli.BoolFlag {
62+ Name : "interactive" ,
63+ Aliases : []string {"i" },
64+ Usage : "use this flag if the command expects some input from the stdin" ,
65+ },
6166 },
6267 Commands : []* cli.Command {
6368 {
@@ -149,7 +154,7 @@ func mainCmd(c *cli.Context) error {
149154
150155 // Launch main command
151156 var childPid int
152- childPid , err = run (ctx , provider , c .Bool ("exit-early" ), c .Args ().Slice ())
157+ childPid , err = run (ctx , provider , c .Bool ("exit-early" ), c .Bool ( "interactive" ), c . Args ().Slice ())
153158 if err != nil {
154159 log .WithError (err ).Error ("failed to run" )
155160 os .Exit (1 )
@@ -188,7 +193,7 @@ func removeZombies(childPid int) {
188193}
189194
190195// run passed command
191- func run (ctx context.Context , provider secrets.Provider , exitEarly bool , commandSlice []string ) (childPid int , err error ) {
196+ func run (ctx context.Context , provider secrets.Provider , exitEarly , interactive bool , commandSlice []string ) (childPid int , err error ) {
192197 var commandStr string
193198 var argsSlice []string
194199
@@ -213,7 +218,15 @@ func run(ctx context.Context, provider secrets.Provider, exitEarly bool, command
213218 cmd .Stdout = os .Stdout
214219 cmd .Stderr = os .Stderr
215220 // create a dedicated pidgroup used to forward signals to the main process and its children
216- cmd .SysProcAttr = & syscall.SysProcAttr {Setpgid : true }
221+ procAttrs := & syscall.SysProcAttr {Setpgid : true }
222+ // rebind stdin if -i flag is set
223+ if interactive {
224+ cmd .Stdin = os .Stdin
225+ // setting 'Foreground' to true will bind current TTY to the child process
226+ procAttrs = & syscall.SysProcAttr {Setpgid : true , Foreground : true }
227+ }
228+ // set child process attributes
229+ cmd .SysProcAttr = procAttrs
217230
218231 // set environment variables
219232 if provider != nil {
0 commit comments