Skip to content

Commit

Permalink
#72 Append extra args if no placeholder is defined in the command
Browse files Browse the repository at this point in the history
  • Loading branch information
zshamrock committed Aug 3, 2018
1 parent 4d463d2 commit 3f7954e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion command/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestGetCommandExtraArgs(t *testing.T) {
followFlags := []string{"", "-f", "--follow"}
commandsData := []map[string]string{
{"name": "logs-extra1", "extra": "rest.log", "command": "tail -f -n 10 logs/rest.log"},
{"name": "logs-extra2", "extra": "5", "command": "tail -f -n 5 logs/app.log"},
{"name": "logs-extra2", "extra": "5", "command": "tail -f -n 5 logs/app.log 5"},
}
for _, followFlag := range followFlags {
for _, commandData := range commandsData {
Expand Down
7 changes: 6 additions & 1 deletion command/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const (
optionalFollowArgsIndex = 0
hostsGroupArgsIndex = 0
commandNameArgsIndex = 1
extraArgsPlaceholder = "%s"
FollowArgName = "follow"
)

Expand Down Expand Up @@ -102,7 +103,11 @@ func getCommand(c *cli.Context, follow bool) core.Command {
extraArgs = strings.Join(args.Tail()[extraArgsIndex:], " ")
}
if extraArgs != "" {
command.Command = fmt.Sprintf(command.Command, extraArgs)
if strings.Contains(command.Command, extraArgsPlaceholder) {
command.Command = fmt.Sprintf(command.Command, extraArgs)
} else {
command.Command += " " + extraArgs
}
}
return command
}
Expand Down

0 comments on commit 3f7954e

Please sign in to comment.