Skip to content

Commit f795b4c

Browse files
RiSKeDjenstopp
authored andcommitted
refactor!: change naming of dutagent config items
Renames YAML field names in dutagent configuration: modules → uses and options → with for improved clarity and consistency with common workflow syntax patterns. Changes: - Added YAML tags to Modules and Options struct fields to map new field names - Updated documentation tables and descriptions to reflect new field names - Migrated all example configuration files to new syntax BREAKING CHANGE: The dutagent configuration changed. Existing configurations must be updated in the following way: From commands: - name: example modules: - name: flash options: file: firmware.bin To commands: - name: example uses: - name: flash with: file: firmware.bin The old field names (modules, options) are no longer supported. Signed-off-by: Fabian Wienand <fabian.wienand@9elements.com>
1 parent b79eff2 commit f795b4c

17 files changed

Lines changed: 56 additions & 58 deletions

cmds/exp/contrib/config-1.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ devices:
66
cmds:
77
status:
88
desc: "Report status"
9-
modules:
9+
uses:
1010
- module: dummy-status
1111
main: true

cmds/exp/contrib/config-2.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ devices:
66
cmds:
77
status:
88
desc: "Report status"
9-
modules:
9+
uses:
1010
- module: dummy-status
1111
main: true
1212
repeat:
1313
desc: "Repeat input"
14-
modules:
14+
uses:
1515
- module: dummy-repeat
1616
main: true

contrib/dutagent-cfg-example.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,36 @@ devices:
66
cmds:
77
status:
88
desc: "Report status"
9-
modules:
9+
uses:
1010
- module: dummy-status
1111
main: true
1212
device2:
1313
desc: "Device 2"
1414
cmds:
1515
status:
1616
desc: "Report status"
17-
modules:
17+
uses:
1818
- module: dummy-status
1919
main: true
2020
repeat:
2121
desc: "Repeat input"
22-
modules:
22+
uses:
2323
- module: dummy-repeat
2424
main: true
2525
device3:
2626
desc: "Device 3"
2727
cmds:
2828
status:
2929
desc: "Report status"
30-
modules:
30+
uses:
3131
- module: dummy-status
3232
main: true
3333
file-transfer:
3434
desc: "Transfer a file"
35-
modules:
35+
uses:
3636
- module: dummy-status
37-
args:
37+
args:
3838
- foo
3939
- bar
4040
- module: dummy-ft
41-
main: true
41+
main: true

docs/dutagent-config.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ could look like.
3434
| Attribute | Type | Default | Description | Mandatory |
3535
|-------------|----------------------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------|
3636
| description | string | | Command description | no |
37-
| Modules | [] [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, though. Exactly one of the modules must be set as the main module. All arguments to a command are passed to its main module. The main modules usage information is also used as the command help text. If a Command is composed of only one module, this module becomes the main module implicitly. | 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, though. Exactly one of the modules must be set as the main module. All arguments to a command are passed to its main module. The main modules usage information is also used as the command help text. If a Command is composed of only one module, this module becomes the main module implicitly. | yes |
3838

3939
### Module
4040

@@ -43,10 +43,10 @@ could look like.
4343
| module | string | | The module's name also serves as its identifier and must be unique. | yes |
4444
| main | bool | false | All arguments to a command are passed to its main module. The main modules usage information is also used as the command help text. Can be omitted, if only one modules exists within the command. | exactly once per command |
4545
| 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 |
46-
| options | 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 |
46+
| 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]
49-
> Refer to option keys of a module in all-lowercase representation of the modules exported fields.
49+
> Refer to `with` keys of a module in all-lowercase representation of the module's exported fields.
5050
> See the respective module's documentation for details.
5151
5252
### Example config file

docs/module_guide.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ _ "github.com/BlindspotSoftware/dutctl/pkg/module/dummy"
5757
```
5858

5959
## Configuration
60-
61-
A module can be dynamically configured when starting a _dutagent_ using the option map in the
62-
[_dutagent_ configuration](./dutagent-config.md#module). A module must be of type `struct` and have the options as
60+
A module can be dynamically configured when starting a _dutagent_ using the `with` map in the
61+
[_dutagent_ configuration](./dutagent-config.md#module). A module must be of type `struct` and have the configuration as
6362
fields. The parser will set the struct fields to match the map keys.
6463

6564
For example, a module like the one below, registered with `ID` = `"my-module"`.
@@ -81,15 +80,15 @@ devices:
8180
cmds:
8281
some-cmd:
8382
desc: My cool module
84-
modules:
83+
uses:
8584
- module: my-module
86-
options:
85+
with:
8786
foo: 42
8887
```
8988
9089
> [!IMPORTANT]
91-
> It is imperative that the module's documentation and Help() function provide a good explanation of its options.
92-
> The option map in the configuration file is generic (string → any type), so it is important that the user knows what
90+
> It is imperative that the module's documentation and Help() function provide a good explanation of its configuration.
91+
> The `with` map in the configuration file is generic (string → any type), so it is important that the user knows what
9392
> values are expected.
9493

9594
The [project's dummy modules](../pkg/module/dummy/dummy_status.go) show all the details of a complete implementation.

pkg/dut/dut.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ type Device struct {
9090
// modules and are executed in the order they are defined.
9191
type Command struct {
9292
Desc string
93-
Modules []Module
93+
Modules []Module `yaml:"uses"`
9494
}
9595

9696
// commandAlias is used when parsing YAML to avoid recursion.
@@ -153,7 +153,7 @@ type ModuleConfig struct {
153153
Name string `yaml:"module"`
154154
Main bool
155155
Args []string
156-
Options map[string]any
156+
Options map[string]any `yaml:"with"`
157157
}
158158

159159
// UnmarshalYAML unmarshals a Module from a YAML node and adds custom validation.
@@ -178,7 +178,7 @@ func (m *Module) UnmarshalYAML(node *yaml.Node) error {
178178
return err
179179
}
180180

181-
// validate Module options
181+
// validate Module configuration
182182
validate := validator.New()
183183

184184
err = validate.Struct(m.Module)

pkg/module/agent/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The agent-status module can be used in a command like so.
1818
cmds:
1919
system-info:
2020
desc: "This simple command reports information about the dutagent system via the agent-status module."
21-
modules:
21+
uses:
2222
- module: agent-status
2323
main: true
2424
```

pkg/module/file/file-example-cfg.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ devices:
88
# Upload any file - preserves directory structure
99
upload:
1010
desc: "Upload file to device"
11-
modules:
11+
uses:
1212
- module: file
1313
main: true
14-
options:
14+
with:
1515
operation: "upload"
1616
# Usage:
1717
# dutctl example-device upload ./build/firmware.bin
@@ -23,10 +23,10 @@ devices:
2323
# Upload with destination configured - arg becomes source
2424
upload-script:
2525
desc: "Upload and install a script"
26-
modules:
26+
uses:
2727
- module: file
2828
main: true
29-
options:
29+
with:
3030
operation: "upload"
3131
destination: "/opt/scripts/install.sh"
3232
permission: "0755" # Make it executable
@@ -37,10 +37,10 @@ devices:
3737
# Download with source configured - arg becomes destination
3838
fetch-logs:
3939
desc: "Download logs from device"
40-
modules:
40+
uses:
4141
- module: file
4242
main: true
43-
options:
43+
with:
4444
operation: "download"
4545
source: "/var/log.txt"
4646
# Usage:
@@ -50,10 +50,10 @@ devices:
5050
# Upload with both paths configured - no arg allowed
5151
upload-config:
5252
desc: "Upload configuration file with fixed paths"
53-
modules:
53+
uses:
5454
- module: file
5555
main: true
56-
options:
56+
with:
5757
operation: "upload"
5858
source: "./configs/device.conf"
5959
destination: "/etc/device/device.conf"

pkg/module/flash/flash-example-cfg.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ devices:
77
flash:
88
desc: |
99
Basic demo of the Flash module.
10-
modules:
10+
uses:
1111
- module: flash
1212
main: true
13-
options:
13+
with:
1414
tool: "/usr/sbin/flashprog"
1515
programmer: "dediprog"

pkg/module/gpio/gpio-example-cfg.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,24 @@ devices:
66
cmds:
77
fire:
88
desc: "Push the big red button"
9-
modules:
9+
uses:
1010
- module: gpio-button
1111
main: true
12-
options:
12+
with:
1313
pin: 9
1414
reset:
1515
desc: "Reset the rocket"
16-
modules:
16+
uses:
1717
- module: gpio-button
1818
main: true
19-
options:
19+
with:
2020
pin: 10
2121
activelow: true
2222
light:
2323
desc: "Turn on the light"
24-
modules:
24+
uses:
2525
- module: gpio-switch
2626
main: true
27-
options:
27+
with:
2828
pin: 11
2929
initial: on

0 commit comments

Comments
 (0)