Skip to content

Commit

Permalink
Fixes the generated commandline for the Command type
Browse files Browse the repository at this point in the history
Signed-off-by: Jake Correnti <[email protected]>
  • Loading branch information
jakecorrenti committed Sep 6, 2023
1 parent 21e3438 commit 4e8d143
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
14 changes: 7 additions & 7 deletions pkg/types/command.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package types

import (
"fmt"
"os/exec"
"strconv"
)

type Command struct {
Expand Down Expand Up @@ -114,7 +114,7 @@ func (c *Command) socketsToCmdline() []string {

for socketFlag, socket := range c.sockets {
if socket != "" {
args = append(args, fmt.Sprintf("-%s %s", socketFlag, socket))
args = append(args, []string{"-" + socketFlag, socket}...)
}
}

Expand All @@ -128,7 +128,7 @@ func (c *Command) forwardInfoToCmdline() []string {
for forwardInfoFlag, forwardInfo := range c.forwardInfo {
for _, i := range forwardInfo {
if i != "" {
args = append(args, fmt.Sprintf("-%s %s", forwardInfoFlag, i))
args = append(args, []string{"-" + forwardInfoFlag, i}...)
}
}
}
Expand All @@ -142,7 +142,7 @@ func (c *Command) endpointsToCmdline() []string {

for _, endpoint := range c.endpoints {
if endpoint != "" {
args = append(args, "-listen "+endpoint)
args = append(args, []string{"-listen", endpoint}...)
}
}

Expand All @@ -163,10 +163,10 @@ func (c *Command) ToCmdline() []string {
}

// mtu
args = append(args, fmt.Sprintf("-mtu %d", c.MTU))
args = append(args, []string{"-mtu", strconv.Itoa(c.MTU)}...)

// ssh-port
args = append(args, fmt.Sprintf("-ssh-port %d", c.SSHPort))
args = append(args, []string{"-ssh-port", strconv.Itoa(c.SSHPort)}...)

// sockets
args = append(args, c.socketsToCmdline()...)
Expand All @@ -176,7 +176,7 @@ func (c *Command) ToCmdline() []string {

// pid-file
if c.PidFile != "" {
args = append(args, "-pid-file "+c.PidFile)
args = append(args, []string{"-pid-file", c.PidFile}...)
}

return args
Expand Down
12 changes: 6 additions & 6 deletions test/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,13 @@ var _ = Describe("command-line format", func() {

cmd := command.ToCmdline()
Expect(cmd).To(Equal([]string{
"-listen unix:///tmp/network.sock",
"-listen", "unix:///tmp/network.sock",
"-debug",
"-mtu 1500",
"-ssh-port 2222",
"-listen-qemu tcp://0.0.0.0:1234",
"-forward-user demouser",
"-pid-file ~/gv-pidfile.txt",
"-mtu", "1500",
"-ssh-port", "2222",
"-listen-qemu", "tcp://0.0.0.0:1234",
"-forward-user", "demouser",
"-pid-file", "~/gv-pidfile.txt",
}))
})
})

0 comments on commit 4e8d143

Please sign in to comment.