Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
yuya-takeyama committed Apr 19, 2016
0 parents commit 4d83474
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/build
/ntimes
/pkg
20 changes: 20 additions & 0 deletions README.md
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
36 changes: 36 additions & 0 deletions main.go
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)
}
}
}
21 changes: 21 additions & 0 deletions main_test.go
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)
}
}
1 change: 1 addition & 0 deletions release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ggallin release --os="linux darwin" --username=yuya-takeyama
5 changes: 5 additions & 0 deletions version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package main

const Version string = "0.0.1"

var GitCommit = ""
25 changes: 25 additions & 0 deletions wercker.yml
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 ./...

0 comments on commit 4d83474

Please sign in to comment.