mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 17:31:43 +00:00
fix extra args handling in sg (#57758)
When running `sg test <target> extra-arg1 extra-arg2 ...`, the extra args are generally appended to the `<target>` command on a new line, which means the extra args are interpreted by the shell as their own command. The user's intent is for them to be appended to the last command in the `<target>` command string, which this commit achieves by trimming trailing whitespace.
This commit is contained in:
parent
7fd4554d91
commit
d1ae5ab487
@ -3,6 +3,7 @@ package sgconf
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
@ -38,6 +39,7 @@ func parseConfig(data []byte) (*Config, error) {
|
||||
|
||||
for name, cmd := range conf.Commands {
|
||||
cmd.Name = name
|
||||
normalizeCmd(&cmd)
|
||||
conf.Commands[name] = cmd
|
||||
}
|
||||
|
||||
@ -48,12 +50,19 @@ func parseConfig(data []byte) (*Config, error) {
|
||||
|
||||
for name, cmd := range conf.Tests {
|
||||
cmd.Name = name
|
||||
normalizeCmd(&cmd)
|
||||
conf.Tests[name] = cmd
|
||||
}
|
||||
|
||||
return &conf, nil
|
||||
}
|
||||
|
||||
func normalizeCmd(cmd *run.Command) {
|
||||
// Trim trailing whitespace so extra args apply to last command (instead of being interpreted as
|
||||
// a new shell command on a separate line).
|
||||
cmd.Cmd = strings.TrimSpace(cmd.Cmd)
|
||||
}
|
||||
|
||||
type Commandset struct {
|
||||
Name string `yaml:"-"`
|
||||
Commands []string `yaml:"commands"`
|
||||
|
||||
Loading…
Reference in New Issue
Block a user