Skip to content

Commit fa9dff2

Browse files
committed
refactor: rename main to interactive throughout codebase
Updated terminology from "main module" to "interactive module" to better reflect the module's purpose of receiving runtime arguments. Signed-off-by: Fabian Wienand <[email protected]>
1 parent 7a38cdc commit fa9dff2

File tree

18 files changed

+101
-102
lines changed

18 files changed

+101
-102
lines changed

cmds/dutagent/rpc.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,16 @@ func (a *rpcService) Details(
115115

116116
var helpStr string
117117

118-
// Find help text: prefer main module's help, otherwise describe all modules
118+
// Find help text: prefer interactive module's help, otherwise describe all modules
119119
for _, module := range cmd.Modules {
120-
if module.Config.Main {
120+
if module.Config.Interactive {
121121
helpStr = module.Help()
122122

123123
break
124124
}
125125
}
126126

127-
// If no main module, provide overview of all modules
127+
// If no interactive module, provide overview of all modules
128128
if helpStr == "" {
129129
var moduleNames []string
130130
for _, module := range cmd.Modules {

cmds/dutagent/states.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@ func findDUTCmd(_ context.Context, args runCmdArgs) (runCmdArgs, fsm.State[runCm
9696
// It returns a slice where each element contains the args for the corresponding module.
9797
// Returns an error if validation fails.
9898
func prepareModuleArgs(cmd dut.Command, runtimeArgs []string) ([][]string, error) {
99-
if len(runtimeArgs) > 0 && cmd.CountMain() == 0 {
99+
if len(runtimeArgs) > 0 && cmd.CountInteractive() == 0 {
100100
return nil, fmt.Errorf("arguments provided but command has no main module to receive them")
101101
}
102102

103103
// Prepare args for each module
104104
moduleArgs := make([][]string, len(cmd.Modules))
105105
for i, module := range cmd.Modules {
106-
if module.Config.Main {
106+
if module.Config.Interactive {
107107
moduleArgs[i] = runtimeArgs
108108
} else {
109109
moduleArgs[i] = module.Config.Args

cmds/dutagent/states_test.go

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ func TestFindDUTCmd(t *testing.T) {
9393
validCmd := pb.Command{Device: "dev1", Command: "echo"}
9494

9595
// Helper to build a dut.Devlist with optional command configuration.
96-
makeDevlist := func(includeCmd bool, cmdModules int, mainCount int) dut.Devlist {
96+
makeDevlist := func(includeCmd bool, cmdModules int, interactiveCount int) dut.Devlist {
9797
devs := make(dut.Devlist)
9898
if includeCmd {
9999
modules := make([]dut.Module, 0, cmdModules)
100100
for i := 0; i < cmdModules; i++ {
101101
m := dut.Module{}
102102
m.Config.Name = fmt.Sprintf("mod%d", i)
103-
if i < mainCount { // mark first mainCount modules as main (can create invalid config)
104-
m.Config.Main = true
103+
if i < interactiveCount { // mark first interactiveCount modules as interactive (can create invalid config)
104+
m.Config.Interactive = true
105105
}
106106
modules = append(modules, m)
107107
}
@@ -152,7 +152,7 @@ func TestFindDUTCmd(t *testing.T) {
152152
wantErrCode: connect.CodeInternal,
153153
},
154154
{
155-
name: "invalid_command_multiple_mains",
155+
name: "invalid_command_multiple_interactives",
156156
cmdMsg: &validCmd,
157157
devs: makeDevlist(true, 2, 2),
158158
wantErrCode: connect.CodeInternal,
@@ -215,12 +215,12 @@ func (m *dummyModule) Run(_ context.Context, _ module.Session, args ...string) e
215215

216216
func TestExecuteModules(t *testing.T) {
217217
type expect struct {
218-
wantErrCode connect.Code // error returned by executeModules state itself
219-
wantNext fsm.State[runCmdArgs]
220-
mainArgs []string // expected args passed to main module
221-
nonMainArgs []string // expected args passed to non-main module (if present)
222-
mainRuns int
223-
nonMainRuns int
218+
wantErrCode connect.Code // error returned by executeModules state itself
219+
wantNext fsm.State[runCmdArgs]
220+
interactiveArgs []string // expected args passed to interactive module
221+
nonInteractiveArgs []string // expected args passed to non-interactive module (if present)
222+
interactiveRuns int
223+
nonInteractiveRuns int
224224
}
225225

226226
tests := []struct {
@@ -231,92 +231,92 @@ func TestExecuteModules(t *testing.T) {
231231
expect expect
232232
}{
233233
{
234-
name: "success_single_main_module",
234+
name: "success_single_interactive_module",
235235
modules: func() []dut.Module {
236236
m := &dummyModule{}
237237
wrap := dut.Module{}
238-
wrap.Config.Name = "mainMod"
239-
wrap.Config.Main = true
238+
wrap.Config.Name = "interactiveMod"
239+
wrap.Config.Interactive = true
240240
wrap.Module = m
241241
return []dut.Module{wrap}
242242
}(),
243243
cmdMsg: &pb.Command{Device: "devX", Command: "cmdY", Args: []string{"a", "b"}},
244-
expect: expect{wantNext: waitModules, mainArgs: []string{"a", "b"}, mainRuns: 1},
244+
expect: expect{wantNext: waitModules, interactiveArgs: []string{"a", "b"}, interactiveRuns: 1},
245245
},
246246
{
247-
name: "success_two_modules_main_and_helper",
247+
name: "success_two_modules_interactive_and_helper",
248248
modules: func() []dut.Module {
249-
main := &dummyModule{}
249+
interactive := &dummyModule{}
250250
helper := &dummyModule{}
251251
w1 := dut.Module{}
252-
w1.Config.Name = "mainMod"
253-
w1.Config.Main = true
254-
w1.Module = main
252+
w1.Config.Name = "interactiveMod"
253+
w1.Config.Interactive = true
254+
w1.Module = interactive
255255
w2 := dut.Module{}
256256
w2.Config.Name = "helperMod"
257-
w2.Config.Main = false
257+
w2.Config.Interactive = false
258258
w2.Config.Args = []string{"conf1"}
259259
w2.Module = helper
260260
return []dut.Module{w1, w2}
261261
}(),
262262
cmdMsg: &pb.Command{Device: "devX", Command: "cmdY", Args: []string{"x", "y"}},
263-
expect: expect{wantNext: waitModules, mainArgs: []string{"x", "y"}, nonMainArgs: []string{"conf1"}, mainRuns: 1, nonMainRuns: 1},
263+
expect: expect{wantNext: waitModules, interactiveArgs: []string{"x", "y"}, nonInteractiveArgs: []string{"conf1"}, interactiveRuns: 1, nonInteractiveRuns: 1},
264264
},
265265
{
266266
name: "module_error_stops_execution",
267267
modules: func() []dut.Module {
268268
bad := &dummyModule{err: errors.New("boom")}
269269
wrap := dut.Module{}
270270
wrap.Config.Name = "badMain"
271-
wrap.Config.Main = true
271+
wrap.Config.Interactive = true
272272
wrap.Module = bad
273273
return []dut.Module{wrap}
274274
}(),
275275
cmdMsg: &pb.Command{Device: "devX", Command: "cmdY"},
276-
expect: expect{wantNext: waitModules, mainRuns: 1},
276+
expect: expect{wantNext: waitModules, interactiveRuns: 1},
277277
},
278278
{
279279
name: "second_module_error_stops_execution",
280280
modules: func() []dut.Module {
281-
main := &dummyModule{} // succeeds
281+
interactive := &dummyModule{} // succeeds
282282
failing := &dummyModule{err: errors.New("helper failed")}
283283
w1 := dut.Module{}
284-
w1.Config.Name = "mainMod"
285-
w1.Config.Main = true
286-
w1.Module = main
284+
w1.Config.Name = "interactiveMod"
285+
w1.Config.Interactive = true
286+
w1.Module = interactive
287287
w2 := dut.Module{}
288288
w2.Config.Name = "helperMod"
289-
w2.Config.Main = false
289+
w2.Config.Interactive = false
290290
w2.Config.Args = []string{"harg"}
291291
w2.Module = failing
292292
return []dut.Module{w1, w2}
293293
}(),
294294
cmdMsg: &pb.Command{Device: "devX", Command: "cmdY", Args: []string{"m1", "m2"}},
295-
expect: expect{wantNext: waitModules, mainArgs: []string{"m1", "m2"}, nonMainArgs: []string{"harg"}, mainRuns: 1, nonMainRuns: 1},
295+
expect: expect{wantNext: waitModules, interactiveArgs: []string{"m1", "m2"}, nonInteractiveArgs: []string{"harg"}, interactiveRuns: 1, nonInteractiveRuns: 1},
296296
},
297297
{
298298
name: "pre_canceled_context_no_module_run",
299299
preCancel: true,
300300
modules: func() []dut.Module {
301301
m := &dummyModule{}
302302
wrap := dut.Module{}
303-
wrap.Config.Name = "mainMod"
304-
wrap.Config.Main = true
303+
wrap.Config.Name = "interactiveMod"
304+
wrap.Config.Interactive = true
305305
wrap.Module = m
306306
return []dut.Module{wrap}
307307
}(),
308308
cmdMsg: &pb.Command{Device: "devX", Command: "cmdY"},
309-
expect: expect{wantNext: waitModules, mainRuns: 0},
309+
expect: expect{wantNext: waitModules, interactiveRuns: 0},
310310
},
311311
}
312312

313313
for _, tt := range tests {
314314
tt := tt
315315
// Extract underlying dummy modules for later inspection
316-
var mainDummy, helperDummy *dummyModule
316+
var interactiveDummy, helperDummy *dummyModule
317317
if len(tt.modules) > 0 {
318318
if dm, ok := tt.modules[0].Module.(*dummyModule); ok {
319-
mainDummy = dm
319+
interactiveDummy = dm
320320
}
321321
}
322322
if len(tt.modules) > 1 {
@@ -386,21 +386,21 @@ func TestExecuteModules(t *testing.T) {
386386
}
387387

388388
// Validate module runs if we have dummy modules
389-
if mainDummy != nil && mainDummy.runCalls != tt.expect.mainRuns {
390-
t.Fatalf("main module runCalls mismatch: want %d got %d", tt.expect.mainRuns, mainDummy.runCalls)
389+
if interactiveDummy != nil && interactiveDummy.runCalls != tt.expect.interactiveRuns {
390+
t.Fatalf("interactive module runCalls mismatch: want %d got %d", tt.expect.interactiveRuns, interactiveDummy.runCalls)
391391
}
392-
if helperDummy != nil && helperDummy.runCalls != tt.expect.nonMainRuns {
393-
t.Fatalf("non-main module runCalls mismatch: want %d got %d", tt.expect.nonMainRuns, helperDummy.runCalls)
392+
if helperDummy != nil && helperDummy.runCalls != tt.expect.nonInteractiveRuns {
393+
t.Fatalf("non-interactive module runCalls mismatch: want %d got %d", tt.expect.nonInteractiveRuns, helperDummy.runCalls)
394394
}
395395

396-
if len(tt.expect.mainArgs) > 0 && mainDummy != nil {
397-
if fmt.Sprint(mainDummy.runArgs) != fmt.Sprint(tt.expect.mainArgs) {
398-
t.Fatalf("main module args mismatch: want %v got %v", tt.expect.mainArgs, mainDummy.runArgs)
396+
if len(tt.expect.interactiveArgs) > 0 && interactiveDummy != nil {
397+
if fmt.Sprint(interactiveDummy.runArgs) != fmt.Sprint(tt.expect.interactiveArgs) {
398+
t.Fatalf("interactive module args mismatch: want %v got %v", tt.expect.interactiveArgs, interactiveDummy.runArgs)
399399
}
400400
}
401-
if len(tt.expect.nonMainArgs) > 0 && helperDummy != nil {
402-
if fmt.Sprint(helperDummy.runArgs) != fmt.Sprint(tt.expect.nonMainArgs) {
403-
t.Fatalf("non-main module args mismatch: want %v got %v", tt.expect.nonMainArgs, helperDummy.runArgs)
401+
if len(tt.expect.nonInteractiveArgs) > 0 && helperDummy != nil {
402+
if fmt.Sprint(helperDummy.runArgs) != fmt.Sprint(tt.expect.nonInteractiveArgs) {
403+
t.Fatalf("non-interactive module args mismatch: want %v got %v", tt.expect.nonInteractiveArgs, helperDummy.runArgs)
404404
}
405405
}
406406

cmds/exp/contrib/config-1.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ devices:
88
desc: "Report status"
99
uses:
1010
- module: dummy-status
11-
main: true
11+
interactive: true

cmds/exp/contrib/config-2.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ devices:
88
desc: "Report status"
99
uses:
1010
- module: dummy-status
11-
main: true
11+
interactive: true
1212
repeat:
1313
desc: "Repeat input"
1414
uses:
1515
- module: dummy-repeat
16-
main: true
16+
interactive: true

contrib/dutagent-cfg-example.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,28 @@ devices:
88
desc: "Report status"
99
uses:
1010
- module: dummy-status
11-
main: true
11+
interactive: true
1212
device2:
1313
desc: "Device 2"
1414
cmds:
1515
status:
1616
desc: "Report status"
1717
uses:
1818
- module: dummy-status
19-
main: true
19+
interactive: true
2020
repeat:
2121
desc: "Repeat input"
2222
uses:
2323
- module: dummy-repeat
24-
main: true
24+
interactive: true
2525
device3:
2626
desc: "Device 3"
2727
cmds:
2828
status:
2929
desc: "Report status"
3030
uses:
3131
- module: dummy-status
32-
main: true
32+
interactive: true
3333
file-transfer:
3434
desc: "Transfer a file"
3535
uses:
@@ -38,4 +38,4 @@ devices:
3838
- foo
3939
- bar
4040
- module: dummy-ft
41-
main: true
41+
interactive: true

docs/dutagent-config.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ could look like.
3434
| Attribute | Type | Default | Description | Mandatory |
3535
|-------------|----------------------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------|
3636
| description | string | | Command description | no |
37-
| uses | [] [Module](#Module) | | A command may be composed of multiple steps to achieve its purpose. The list of modules represent these steps. The order of this list is important. At most one module may be set as the main module. If a main module is present, all arguments to the command are passed to it, and its usage information is used as the command help text. | yes |
37+
| uses | [] [Module](#Module) | | A command may be composed of multiple steps to achieve its purpose. The list of modules represent these steps. The order of this list is important. At most one module may be set as the interactive module. If an interactive module is present, all arguments to the command are passed to it, and its usage information is used as the command help text. | yes |
3838

3939
### Module
4040

4141
| Attribute | Type | Default | Description | Mandatory |
4242
|-----------|----------------|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------|
4343
| module | string | | The module's name also serves as its identifier and must be unique. | yes |
44-
| main | bool | false | Marks this module as the main module. All runtime arguments to a command are passed to its main module. The main module's usage information is also used as the command help text. | 0 or 1 times per command |
45-
| args | []string | nil | If a module is **not** an commands main module, it does not get any arguments passed at runtime, instead arguments can be passed here. | no, only applies if `main` is set |
44+
| interactive | bool | false | Marks this module as the interactive module. All runtime arguments to a command are passed to its interactive module. The interactive module's usage information is also used as the command help text. | 0 or 1 times per command |
45+
| args | []string | nil | If a module is **not** an commands interactive module, it does not get any arguments passed at runtime, instead arguments can be passed here. | no, only applies if `main` is set |
4646
| with | map[string]any | | A module can be configured via key-value pairs. The type of the value is generic and depends on the implementation of the module. | yes |
4747

4848
> [!IMPORTANT]

0 commit comments

Comments
 (0)