mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-03 06:01:52 +08:00
Quote command arguments if they have a space (#1892)
This commit is contained in:
parent
f5549db85d
commit
1571b10b84
@ -108,6 +108,20 @@ func (b *BaseBuilder) CleanUp() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func commandPrettifier(args []string) string {
|
||||||
|
// If we have a single argument, just return it
|
||||||
|
if len(args) == 1 {
|
||||||
|
return args[0]
|
||||||
|
}
|
||||||
|
// If an argument contains a space, quote it
|
||||||
|
for i, arg := range args {
|
||||||
|
if strings.Contains(arg, " ") {
|
||||||
|
args[i] = fmt.Sprintf("\"%s\"", arg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return strings.Join(args, " ")
|
||||||
|
}
|
||||||
|
|
||||||
func (b *BaseBuilder) OutputFilename(options *Options) string {
|
func (b *BaseBuilder) OutputFilename(options *Options) string {
|
||||||
outputFile := options.OutputFile
|
outputFile := options.OutputFile
|
||||||
if outputFile == "" {
|
if outputFile == "" {
|
||||||
@ -270,7 +284,7 @@ func (b *BaseBuilder) CompileProject(options *Options) error {
|
|||||||
cmd := exec.Command(compiler, commands.AsSlice()...)
|
cmd := exec.Command(compiler, commands.AsSlice()...)
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
if verbose {
|
if verbose {
|
||||||
println(" Build command:", compiler, commands.Join(" "))
|
println(" Build command:", compiler, commandPrettifier(commands.AsSlice()))
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
}
|
}
|
||||||
// Set the directory
|
// Set the directory
|
||||||
|
@ -35,3 +35,34 @@ func TestUpdateEnv(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_commandPrettifier(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
input []string
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "empty",
|
||||||
|
input: []string{},
|
||||||
|
want: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "one arg",
|
||||||
|
input: []string{"one"},
|
||||||
|
want: "one",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "args where one has spaces",
|
||||||
|
input: []string{"one", "two three"},
|
||||||
|
want: `one "two three"`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
if got := commandPrettifier(tt.input); got != tt.want {
|
||||||
|
t.Errorf("commandPrettifier() = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user