aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan McNulty <bryanmcnulty@protonmail.com>2025-04-27 08:53:36 -0500
committerBryan McNulty <bryanmcnulty@protonmail.com>2025-04-27 08:53:36 -0500
commit2364d1454decf7b09de42d6de1c83d3e1004df3c (patch)
tree2de213b292f3282ba56e4c99df5c230a31f29c16
parentf1943574d2121e695332b6317a7320b479fd8936 (diff)
downloadgoexec-2364d1454decf7b09de42d6de1c83d3e1004df3c.tar.gz
goexec-2364d1454decf7b09de42d6de1c83d3e1004df3c.zip
IO: remove trailing whitespace from commands
-rw-r--r--pkg/goexec/io.go115
1 files changed, 58 insertions, 57 deletions
diff --git a/pkg/goexec/io.go b/pkg/goexec/io.go
index 1d4358f..c8ad417 100644
--- a/pkg/goexec/io.go
+++ b/pkg/goexec/io.go
@@ -1,98 +1,99 @@
package goexec
import (
- "context"
- "fmt"
- "io"
- "strings"
+ "context"
+ "fmt"
+ "io"
+ "strings"
)
type OutputProvider interface {
- GetOutput(ctx context.Context, writer io.Writer) (err error)
- Clean(ctx context.Context) (err error)
+ GetOutput(ctx context.Context, writer io.Writer) (err error)
+ Clean(ctx context.Context) (err error)
}
type ExecutionIO struct {
- Cleaner
+ Cleaner
- Input *ExecutionInput
- Output *ExecutionOutput
+ Input *ExecutionInput
+ Output *ExecutionOutput
}
type ExecutionOutput struct {
- NoDelete bool
- RemotePath string
- Provider OutputProvider
- Writer io.WriteCloser
+ NoDelete bool
+ RemotePath string
+ Provider OutputProvider
+ Writer io.WriteCloser
}
type ExecutionInput struct {
- StageFile io.ReadCloser
- Executable string
- ExecutablePath string
- Arguments string
- Command string
+ StageFile io.ReadCloser
+ Executable string
+ ExecutablePath string
+ Arguments string
+ Command string
}
func (execIO *ExecutionIO) GetOutput(ctx context.Context) (err error) {
- if execIO.Output.Provider != nil {
- return execIO.Output.Provider.GetOutput(ctx, execIO.Output.Writer)
- }
- return nil
+ if execIO.Output.Provider != nil {
+ return execIO.Output.Provider.GetOutput(ctx, execIO.Output.Writer)
+ }
+ return nil
}
func (execIO *ExecutionIO) Clean(ctx context.Context) (err error) {
- if execIO.Output.Provider != nil {
- return execIO.Output.Provider.Clean(ctx)
- }
- return nil
+ if execIO.Output.Provider != nil {
+ return execIO.Output.Provider.Clean(ctx)
+ }
+ return nil
}
func (execIO *ExecutionIO) CommandLine() (cmd []string) {
- if execIO.Output.Provider != nil && execIO.Output.RemotePath != "" {
- return []string{
- `C:\Windows\System32\cmd.exe`,
- fmt.Sprintf(`/C %s > %s 2>&1`, execIO.Input.String(), execIO.Output.RemotePath),
- }
- }
- return execIO.Input.CommandLine()
+ if execIO.Output.Provider != nil && execIO.Output.RemotePath != "" {
+ return []string{
+ `C:\Windows\System32\cmd.exe`,
+ fmt.Sprintf(`/C %s > %s 2>&1`, execIO.Input.String(), execIO.Output.RemotePath),
+ }
+ }
+ return execIO.Input.CommandLine()
}
-func (execIO *ExecutionIO) String() string {
- cmd := execIO.CommandLine()
-
- // Ensure that executable paths are quoted
- if strings.Contains(cmd[0], " ") {
- return fmt.Sprintf(`%q %s`, cmd[0], strings.Join(cmd[1:], " "))
- }
- return strings.Join(cmd, " ")
+func (execIO *ExecutionIO) String() (str string) {
+ cmd := execIO.CommandLine()
+ // Ensure that executable paths are quoted
+ if strings.Contains(cmd[0], " ") {
+ str = fmt.Sprintf(`%q %s`, cmd[0], strings.Join(cmd[1:], " "))
+ } else {
+ str = strings.Join(cmd, " ")
+ }
+ return strings.Trim(str, " \t\n\r") // trim whitespace
}
func (i *ExecutionInput) CommandLine() (cmd []string) {
- cmd = make([]string, 2)
- cmd[1] = i.Arguments
+ cmd = make([]string, 2)
+ cmd[1] = i.Arguments
- switch {
- case i.Command != "":
- return strings.SplitN(i.Command, " ", 2)
+ switch {
+ case i.Command != "":
+ return strings.SplitN(i.Command, " ", 2)
- case i.ExecutablePath != "":
- cmd[0] = i.ExecutablePath
+ case i.ExecutablePath != "":
+ cmd[0] = i.ExecutablePath
- case i.Executable != "":
- cmd[0] = i.Executable
- }
+ case i.Executable != "":
+ cmd[0] = i.Executable
+ }
- return cmd
+ return cmd
}
func (i *ExecutionInput) String() string {
- return strings.Join(i.CommandLine(), " ")
+ return strings.Join(i.CommandLine(), " ")
}
func (i *ExecutionInput) Reader() (reader io.Reader) {
- if i.StageFile != nil {
- return i.StageFile
- }
- return strings.NewReader(i.String())
+ if i.StageFile != nil {
+ return i.StageFile
+ }
+ return strings.NewReader(i.String())
}