Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying of command by args #4

Merged
merged 2 commits into from Jan 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
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
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
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