Skip to content

Commit a5acb8f

Browse files
Jens DrenhausJens Drenhaus
authored andcommitted
refactor: modules use session.Print/f/ln functions
Signed-off-by: Jens Drenhaus <jens.drenhaus@blindspot.software>
1 parent 3432675 commit a5acb8f

7 files changed

Lines changed: 20 additions & 29 deletions

File tree

pkg/module/agent/status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (m *Status) Run(_ context.Context, s module.Session, _ ...string) error {
5858
return fmt.Errorf("failed to run uname: %v", err)
5959
}
6060

61-
s.Print(out.String())
61+
s.Println(out.String())
6262

6363
return nil
6464
}

pkg/module/dummy/dummy_file_transfer.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,16 @@ func (d *FT) Deinit() error {
5151
func (d *FT) Run(_ context.Context, s module.Session, args ...string) error {
5252
log.Println("dummy.FT module: Run called")
5353

54-
s.Print("Hello from dummy file transfer module")
55-
56-
str := fmt.Sprintf("Called with %d arguments", len(args))
57-
s.Print(str)
54+
s.Println("Hello from dummy file transfer module")
55+
s.Printf("Called with %d arguments\n", len(args))
5856

5957
const expectedArgsCnt = 2
6058
if len(args) != expectedArgsCnt {
6159
return fmt.Errorf("expected 2 arguments, got %d", len(args))
6260
}
6361

6462
inFile := args[0]
65-
str = fmt.Sprintf("Requesting file %q passed in arg[0] as input", inFile)
66-
s.Print(str)
63+
s.Printf("Requesting file %q passed in arg[0] as input\n", inFile)
6764

6865
fileReader, err := s.RequestFile(inFile)
6966
if err != nil {
@@ -95,8 +92,7 @@ func (d *FT) Run(_ context.Context, s module.Session, args ...string) error {
9592
return fmt.Errorf("failed to send file: %v", err)
9693
}
9794

98-
str = fmt.Sprintf("File operated successfully, delivered %q as passed in arg[1] as output", outFile)
99-
s.Print(str)
95+
s.Printf("File operated successfully, delivered %q as passed in arg[1] as output\n", outFile)
10096

10197
return nil
10298
}

pkg/module/dummy/dummy_status.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package dummy
77

88
import (
99
"context"
10-
"fmt"
1110
"log"
1211

1312
"github.com/BlindspotSoftware/dutctl/pkg/module"
@@ -48,14 +47,11 @@ func (d *Status) Deinit() error {
4847
func (d *Status) Run(_ context.Context, s module.Session, args ...string) error {
4948
log.Println("dummy.Status module: Run called")
5049

51-
s.Print("Hello from dummy status module")
52-
53-
str := fmt.Sprintf("Called with %d arguments", len(args))
54-
s.Print(str)
50+
s.Println("Hello from dummy status module")
51+
s.Printf("Called with %d arguments\n", len(args))
5552

5653
for i, arg := range args {
57-
str := fmt.Sprintf("Arg %d: %s", i, arg)
58-
s.Print(str)
54+
s.Printf("Arg %d: %s\n", i, arg)
5955
}
6056

6157
return nil

pkg/module/gpio/gpio.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func (b *Button) Run(_ context.Context, s module.Session, args ...string) error
169169
return err
170170
}
171171

172-
s.Print(fmt.Sprintf("Button pressed for %s", duration))
172+
s.Printf("Button pressed for %s\n", duration)
173173

174174
return nil
175175
}

pkg/module/ipmi/ipmi.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func (i *IPMI) Run(ctx context.Context, s module.Session, args ...string) error
134134
}
135135

136136
if len(args) == 0 {
137-
s.Print("No command specified. Try 'help' for usage.")
137+
s.Println("No command specified. Try 'help' for usage.")
138138

139139
return nil
140140
}
@@ -147,8 +147,8 @@ func (i *IPMI) Run(ctx context.Context, s module.Session, args ...string) error
147147
case status:
148148
return i.handleStatusCommand(ctx, s)
149149
default:
150-
s.Print("Unknown command: " + command)
151-
s.Print("Available commands: on, off, cycle, reset, status")
150+
s.Println("Unknown command: " + command)
151+
s.Println("Available commands: on, off, cycle, reset, status")
152152

153153
return nil
154154
}
@@ -180,7 +180,7 @@ func (i *IPMI) handlePowerCommand(ctx context.Context, s module.Session, command
180180
return fmt.Errorf("power %s command failed: %v", command, err)
181181
}
182182

183-
s.Print(message)
183+
s.Println(message)
184184

185185
return nil
186186
}
@@ -196,7 +196,7 @@ func (i *IPMI) handleStatusCommand(ctx context.Context, s module.Session) error
196196
powerStatus = "On"
197197
}
198198

199-
s.Print(fmt.Sprintf("Device power status: %s", powerStatus))
199+
s.Printf("Device power status: %s\n", powerStatus)
200200

201201
return nil
202202
}

pkg/module/pdu/pdu.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func (p *PDU) Run(ctx context.Context, s module.Session, args ...string) error {
113113
}
114114

115115
if len(args) == 0 {
116-
s.Print("No command specified. Call 'help' for usage.")
116+
s.Println("No command specified. Call 'help' for usage.")
117117

118118
return nil
119119
}
@@ -126,8 +126,8 @@ func (p *PDU) Run(ctx context.Context, s module.Session, args ...string) error {
126126
case status:
127127
return p.status(ctx, s)
128128
default:
129-
s.Print("Unknown command: " + cmd)
130-
s.Print("Available commands: on, off, toggle, status")
129+
s.Println("Unknown command: " + cmd)
130+
s.Println("Available commands: on, off, toggle, status")
131131

132132
return nil
133133
}
@@ -176,7 +176,7 @@ func (p *PDU) setPower(ctx context.Context, s module.Session, state string) erro
176176
}
177177
defer resp.Body.Close()
178178

179-
s.Print(fmt.Sprintf("PDU outlet%d power set to '%s' successfully", p.Outlet, state))
179+
s.Printf("PDU outlet%d power set to '%s' successfully\n", p.Outlet, state)
180180

181181
return nil
182182
}
@@ -198,7 +198,7 @@ func (p *PDU) status(ctx context.Context, s module.Session) error {
198198
return err
199199
}
200200

201-
s.Print(fmt.Sprintf("PDU outlet%d state: %s", p.Outlet, outletValue))
201+
s.Printf("PDU outlet%d state: %s\n", p.Outlet, outletValue)
202202

203203
return nil
204204
}

pkg/module/time/wait.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ func (w *Wait) Run(_ context.Context, s module.Session, args ...string) error {
104104
duration = w.duration
105105
}
106106

107-
str := fmt.Sprintf("Waiting for %s", duration)
108-
s.Print(str)
107+
s.Printf("Waiting for %s\n", duration)
109108

110109
time.Sleep(duration)
111110

0 commit comments

Comments
 (0)