From 3f7954e8797c3b26e6ad60405f983a7cadcdffb0 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kazlou Date: Fri, 3 Aug 2018 14:46:01 +0300 Subject: [PATCH] #72 Append extra args if no placeholder is defined in the command --- command/command_test.go | 2 +- command/run.go | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/command/command_test.go b/command/command_test.go index 810e141..a71164c 100644 --- a/command/command_test.go +++ b/command/command_test.go @@ -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 { diff --git a/command/run.go b/command/run.go index 2ba600c..28f4dbe 100644 --- a/command/run.go +++ b/command/run.go @@ -19,6 +19,7 @@ const ( optionalFollowArgsIndex = 0 hostsGroupArgsIndex = 0 commandNameArgsIndex = 1 + extraArgsPlaceholder = "%s" FollowArgName = "follow" ) @@ -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 }