Skip to content

Commit

Permalink
add stdin pass
Browse files Browse the repository at this point in the history
  • Loading branch information
seletskiy committed May 30, 2016
1 parent 437cbeb commit ba4074b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
22 changes: 22 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"io"
"os"
"os/user"
"strings"
Expand Down Expand Up @@ -92,6 +93,7 @@ Options:
[default: /var/run/orgalorg/files/$RUNID]
-u --user <user> Username used for connecting to all hosts by default.
[default: $USER]
-i --stdin <file> Pass specified file as input for the command.
-q --quiet Be quiet, in command mode do not use prefixes.
-v --verbose Print debug information on stderr.
-V --version Print program version.
Expand Down Expand Up @@ -204,6 +206,7 @@ func command(args map[string]interface{}) error {
var (
lockFile = args["--lock-file"].(string)
commandToRun = args["<command>"].([]string)
stdin, _ = args["--stdin"].(string)
)

runners, err := createRunnerFactory(args)
Expand Down Expand Up @@ -248,6 +251,25 @@ func command(args map[string]interface{}) error {
)
}

if stdin != "" {
inputFile, err := os.Open(stdin)
if err != nil {
return hierr.Errorf(
err,
`can't open file for passing as stdin: '%s'`,
inputFile,
)
}

_, err = io.Copy(execution.stdin, inputFile)
if err != nil {
return hierr.Errorf(
err,
`can't copy input file to the execution processes`,
)
}
}

err = execution.wait()
if err != nil {
return hierr.Errorf(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
tests:ensure :orgalorg-key -C -- wc -l

containers:do tests:assert-stdout "0"

tests:ensure :orgalorg-key -C -i <(echo 1) -- wc -l

containers:do tests:assert-stdout "1"

0 comments on commit ba4074b

Please sign in to comment.