Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slim down the Executor interface #393

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.18
require (
dario.cat/mergo v1.0.0
github.com/Jeffail/gabs/v2 v2.7.0
github.com/bmc-toolbox/common v0.0.0-20240805193945-ce25765471a7
github.com/bmc-toolbox/common v0.0.0-20240806132831-ba8adc6a35e3
github.com/bombsimon/logrusr/v2 v2.0.1
github.com/ghodss/yaml v1.0.0
github.com/go-logr/logr v1.4.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ github.com/VictorLowther/simplexml v0.0.0-20180716164440-0bff93621230 h1:t95Grn2
github.com/VictorLowther/simplexml v0.0.0-20180716164440-0bff93621230/go.mod h1:t2EzW1qybnPDQ3LR/GgeF0GOzHUXT5IVMLP2gkW1cmc=
github.com/VictorLowther/soap v0.0.0-20150314151524-8e36fca84b22 h1:a0MBqYm44o0NcthLKCljZHe1mxlN6oahCQHHThnSwB4=
github.com/VictorLowther/soap v0.0.0-20150314151524-8e36fca84b22/go.mod h1:/B7V22rcz4860iDqstGvia/2+IYWXf3/JdQCVd/1D2A=
github.com/bmc-toolbox/common v0.0.0-20240723135842-8256ba794af8 h1:KK812W5Tpk0n5qcS0vZ0IYqhoZNkV66NuCIon99OGQ8=
github.com/bmc-toolbox/common v0.0.0-20240723135842-8256ba794af8/go.mod h1:Cdnkm+edb6C0pVkyCrwh3JTXAe0iUF9diDG/DztPI9I=
github.com/bmc-toolbox/common v0.0.0-20240805193945-ce25765471a7 h1:+NcnInwZxn25daBCb3d1y3x9QF23uob1ghdiimj2Dwo=
github.com/bmc-toolbox/common v0.0.0-20240805193945-ce25765471a7/go.mod h1:Cdnkm+edb6C0pVkyCrwh3JTXAe0iUF9diDG/DztPI9I=
github.com/bmc-toolbox/common v0.0.0-20240806132831-ba8adc6a35e3 h1:/BjZSX/sphptIdxpYo4wxAQkgMLyMMgfdl48J9DKNeE=
github.com/bmc-toolbox/common v0.0.0-20240806132831-ba8adc6a35e3/go.mod h1:Cdnkm+edb6C0pVkyCrwh3JTXAe0iUF9diDG/DztPI9I=
github.com/bombsimon/logrusr/v2 v2.0.1 h1:1VgxVNQMCvjirZIYaT9JYn6sAVGVEcNtRE0y4mvaOAM=
github.com/bombsimon/logrusr/v2 v2.0.1/go.mod h1:ByVAX+vHdLGAfdroiMg6q0zgq2FODY2lc5YJvzmOJio=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
Expand Down
42 changes: 0 additions & 42 deletions internal/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,9 @@ type Executor interface {
ExecWithContext(context.Context) (*Result, error)
SetArgs([]string)
SetEnv([]string)
SetQuiet()
SetVerbose()
GetCmd() string
DisableBinCheck()
SetStdin(io.Reader)
CmdPath() string
CheckExecutable() error
// for tests
SetStdout([]byte)
SetStderr([]byte)
SetExitCode(int)
}

func NewExecutor(cmd string) Executor {
Expand Down Expand Up @@ -58,12 +50,6 @@ func (e *Execute) GetCmd() string {
return strings.Join(cmd, " ")
}

// CmdPath returns the absolute path to the executable
// this means the caller should not have disabled CheckBin.
func (e *Execute) CmdPath() string {
return e.Cmd
}

// SetArgs sets the command args
func (e *Execute) SetArgs(a []string) {
e.Args = a
Expand All @@ -74,38 +60,10 @@ func (e *Execute) SetEnv(env []string) {
e.Env = env
}

// SetQuiet lowers the verbosity
func (e *Execute) SetQuiet() {
e.Quiet = true
}

// SetVerbose does whats it says
func (e *Execute) SetVerbose() {
e.Quiet = false
}

// SetStdin sets the reader to the command stdin
func (e *Execute) SetStdin(r io.Reader) {
e.Stdin = r
}

// DisableBinCheck disables validating the binary exists and is executable
func (e *Execute) DisableBinCheck() {
e.CheckBin = false
}

// SetStdout doesn't do much, is around for tests
func (e *Execute) SetStdout(_ []byte) {
}

// SetStderr doesn't do much, is around for tests
func (e *Execute) SetStderr(_ []byte) {
}

// SetExitCode doesn't do much, is around for tests
func (e *Execute) SetExitCode(_ int) {
}

// ExecWithContext executes the command and returns the Result object
func (e *Execute) ExecWithContext(ctx context.Context) (result *Result, err error) {
if e.CheckBin {
Expand Down
1 change: 0 additions & 1 deletion internal/executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ func Test_Stdin(t *testing.T) {
e.Cmd = "grep"
e.Args = []string{"hello"}
e.Stdin = bytes.NewReader([]byte("hello"))
e.SetQuiet()

result, err := e.ExecWithContext(context.Background())
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion internal/sum/sum.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ func New(host, user, pass string, opts ...Option) (*Sum, error) {

e := ex.NewExecutor(sum.SumPath)
e.SetEnv([]string{"LC_ALL=C.UTF-8"})
// e.SetQuiet()
sum.Executor = e

return sum, nil
Expand Down
Loading