Skip to content

Commit

Permalink
Merge pull request #4 from k1LoW/allow-args
Browse files Browse the repository at this point in the history
Allow specifying of command by args
  • Loading branch information
k1LoW authored Jan 17, 2019
2 parents d74dbfd + a457ce4 commit 85fb824
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@ Key features of `evry` are:
$ [STDIN] | evry [-l N or -s N] -c [COMMAND]
```

or

``` console
$ [STDIN] | evry [-l N or -s N] -- [COMMAND]
```

### Count number of requests every 10 seconds

``` console
$ tail -F access.log | evry -s 10 -c 'wc -l'
$ tail -F access.log | evry -s 10 -- wc -l
```

### Show top 5 access rank every 1000 lines
Expand Down
7 changes: 6 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,13 @@ var rootCmd = &cobra.Command{
ctx := context.Background()
var s splitter.Splitter
var err error
var c []string

c := []string{"sh", "-c", command}
if len(args) > 0 {
c = args
} else {
c = []string{"sh", "-c", command}
}

if line > 0 {
s, err = splitter.NewLineSplitter(ctx, line, c, timeout)
Expand Down
9 changes: 9 additions & 0 deletions evry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ func TestPipe(t *testing.T) {
}
}

func TestPipeWithArgs(t *testing.T) {
cmd := `echo -e "b\nc\na\ne\nd" | ./evry -l 10 -- sh -c 'cat | sort | head -3'`
want := "a\nb\nc\n"
got := execCmd(cmd)
if got != want {
t.Errorf("\nwant %q\ngot %q", want, got)
}
}

func execCmd(cmd string) string {
b, _ := exec.Command(os.Getenv("SHELL"), "-c", cmd).Output()
return string(b)
Expand Down

0 comments on commit 85fb824

Please sign in to comment.