-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4d83474
Showing
7 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/build | ||
/ntimes | ||
/pkg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# ntimes | ||
|
||
Command to execute command N times | ||
|
||
## Usage | ||
|
||
``` | ||
$ ntimes 3 echo foo bar baz | ||
foo bar baz | ||
foo bar baz | ||
foo bar baz | ||
``` | ||
|
||
## Author | ||
|
||
Yuya Takeyama | ||
|
||
## License | ||
|
||
The MIT License |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package main | ||
|
||
import ( | ||
"io" | ||
"os" | ||
"os/exec" | ||
"strconv" | ||
) | ||
|
||
const AppName = "ntimes" | ||
|
||
func main() { | ||
cnt, err := strconv.Atoi(os.Args[1]) | ||
cmdName := os.Args[2] | ||
cmdArgs := os.Args[3:] | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
ntimes(cnt, cmdName, cmdArgs, os.Stdin, os.Stdout, os.Stderr) | ||
} | ||
|
||
func ntimes(cnt int, cmdName string, cmdArgs []string, stdin io.Reader, stdout io.Writer, stderr io.Writer) { | ||
for i := 0; i < cnt; i++ { | ||
cmd := exec.Command(cmdName, cmdArgs...) | ||
cmd.Stdin = stdin | ||
cmd.Stdout = stdout | ||
cmd.Stderr = stderr | ||
err := cmd.Run() | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
) | ||
|
||
func TestNtimes(t *testing.T) { | ||
stdin := new(bytes.Buffer) | ||
stdout := new(bytes.Buffer) | ||
stderr := new(bytes.Buffer) | ||
|
||
ntimes(3, "echo", []string{"foo", "bar", "baz"}, stdin, stdout, stderr) | ||
|
||
expected := "foo bar baz\nfoo bar baz\nfoo bar baz\n" | ||
actual := stdout.String() | ||
|
||
if actual != expected { | ||
t.Error("The result does not match\nExpected:\n" + expected + "\nActual:\n" + actual) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ggallin release --os="linux darwin" --username=yuya-takeyama |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package main | ||
|
||
const Version string = "0.0.1" | ||
|
||
var GitCommit = "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
box: wercker/golang | ||
services: | ||
- wercker/mysql | ||
build: | ||
steps: | ||
- setup-go-workspace | ||
- script: | ||
name: go get | ||
code: | | ||
cd $WERCKER_SOURCE_DIR | ||
go version | ||
go get -t ./... | ||
- script: | ||
name: go build | ||
code: | | ||
go build ./... | ||
- script: | ||
name: go test | ||
code: | | ||
export DB2YAML_MYSQL_HOST=$WERCKER_MYSQL_HOST | ||
export DB2YAML_MYSQL_PORT=$WERCKER_MYSQL_PORT | ||
export DB2YAML_MYSQL_USERNAME=$WERCKER_MYSQL_USERNAME | ||
export DB2YAML_MYSQL_PASSWORD=$WERCKER_MYSQL_PASSWORD | ||
export DB2YAML_MYSQL_DATABASE=$WERCKER_MYSQL_DATABASE | ||
go test ./... |