You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Commands can now declare named arguments and distribute them to modules
using ${argname} template syntax. This enables sharing arguments across
multiple modules in a command.
Signed-off-by: Fabian Wienand <[email protected]>
This guide explains the three ways to handle arguments in dutctl commands: non-interactive, interactive, and templating.
4
+
5
+
## Three Mutually Exclusive Approaches
6
+
7
+
Commands support three approaches for arguments. **These approaches are mutually exclusive** - a command must use exactly one:
8
+
9
+
1.**Non-Interactive Commands** - Static values only, no runtime arguments
10
+
2.**Interactive Commands** - Single interactive module receives all runtime arguments
11
+
3.**Command-Level Templating** - Named arguments distributed to modules via templates
12
+
13
+
You cannot mix approaches (e.g., a command cannot have both an interactive module AND command-level args).
14
+
15
+
## Non-Interactive Commands
16
+
17
+
For commands without runtime arguments, you specify static values directly in module args:
18
+
19
+
```yaml
20
+
devices:
21
+
my-device:
22
+
cmds:
23
+
power-cycle:
24
+
desc: "Power cycle the device"
25
+
modules:
26
+
- module: gpio-switch
27
+
args: ["power-pin", "off"]
28
+
- module: time-wait
29
+
args: ["2000"]
30
+
- module: gpio-switch
31
+
args: ["power-pin", "on"]
32
+
```
33
+
34
+
Usage:
35
+
36
+
```bash
37
+
dutctl run my-device power-cycle
38
+
```
39
+
40
+
No runtime arguments needed - all values are configured in the YAML.
41
+
42
+
## Interactive Commands
43
+
44
+
Commands with an interactive module pass all runtime arguments directly to that module:
45
+
46
+
```yaml
47
+
devices:
48
+
my-device:
49
+
cmds:
50
+
run-command:
51
+
desc: "Run shell command"
52
+
modules:
53
+
- module: shell
54
+
interactive: true
55
+
```
56
+
57
+
Usage:
58
+
59
+
```bash
60
+
dutctl run my-device run-command ls -la /tmp
61
+
```
62
+
63
+
The interactive module receives: `["ls", "-la", "/tmp"]`
64
+
65
+
All runtime arguments go to the interactive module - you cannot have multiple interactive modules in one command.
66
+
67
+
## Command-Level Templating
68
+
69
+
Declare named arguments at the command level and distribute them to modules using `${arg-name}` template syntax. Arguments are mapped positionally in declaration order.
70
+
71
+
```yaml
72
+
flash-firmware:
73
+
desc: "Flash firmware to device"
74
+
args:
75
+
- name: firmware-file
76
+
desc: "Path to firmware binary"
77
+
- name: backup-path
78
+
desc: "Backup location"
79
+
modules:
80
+
- module: shell
81
+
args: ["flashrom", "-r", "${backup-path}"]
82
+
- module: file
83
+
args: ["${firmware-file}", "/tmp/fw.bin"]
84
+
- module: flash
85
+
args: ["/tmp/fw.bin"]
86
+
```
87
+
88
+
Usage: `dutctl run device flash-firmware fw.bin /backup/old.bin`
89
+
90
+
Templates can be embedded in strings (`/configs/${name}.yaml`) and mixed with static values (`["${file}", "static", "${other}"]`).
91
+
92
+
## Examples
93
+
94
+
### Flash with Verification
95
+
96
+
```yaml
97
+
flash-verify:
98
+
desc: "Flash firmware and verify"
99
+
args:
100
+
- name: firmware-path
101
+
desc: "Path to firmware binary"
102
+
modules:
103
+
- module: file
104
+
args: ["${firmware-path}", "/tmp/fw.bin"]
105
+
- module: flash
106
+
args: ["/tmp/fw.bin"]
107
+
- module: time-wait
108
+
args: ["500"]
109
+
- module: shell
110
+
args: ["flashrom", "-v", "/tmp/fw.bin"]
111
+
```
112
+
113
+
```bash
114
+
dutctl run device flash-verify /path/to/firmware.bin
Copy file name to clipboardExpand all lines: docs/dutagent-config.md
+25-2Lines changed: 25 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,14 +6,14 @@ The configuration mainly consists of a list of devices connected to an agent and
6
6
for those devices. Commands are meant to be the high-level tasks you want to perform on the device, e.g.
7
7
"Flash the firmware with the given image." To achieve this high-level task, commands can be built up of one or multiple
8
8
_Modules_. Modules represent the basic operations and represent the actual implementation for the hardware interaction.
9
-
The implementation of a Module determines its capabilities and also exposes information on how to use and configure it.
9
+
The implementation of a Module determines its capabilities and also exposes information on how to use and configure it.
10
10
11
11
The DUT Control project offers a collection of Module implementations but also allows for easy integration of [custom modules](./module_guide.md).
12
12
Often a _Command_ can consist of only one _Module_ to get the job done, e.g., power cycles the device. But in some cases
13
13
like the flash example mentioned earlier, eventually it is mandatory to toggle some GPIOs before doing the actual SPI flash
14
14
operation. In this case the command is built up of a Module dealing with GPIO manipulation and a Module performing a
15
15
flash writing with a specific programmer. See the second device in the [example](#example-config-file) down below on what this
16
-
could look like.
16
+
could look like. Commands support three approaches for arguments: non-interactive with static values, interactive modules that receive all runtime arguments directly, and command-level argument templating that distributes named arguments to modules via template syntax (see [Command Argument Templating](./command-arg-templating.md)).
| description | string || Command description | no |
37
+
<<<<<<< HEAD
37
38
| 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 |
39
+
=======
40
+
| args |[][Argument](#command-arguments) || Named arguments that can be passed to the command at runtime and distributed to modules via template syntax. Arguments are mapped positionally in declaration order. **Cannot be used with interactive modules** - use one or the other. | no |
41
+
| 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. At most one module may be set as the interactive module. If an interactive module is present, all runtime arguments are passed to it. If command-level args are declared, they are distributed to non-interactive modules via template substitution. | yes |
42
+
43
+
### Command Arguments
44
+
45
+
Command arguments define named parameters that can be passed at runtime and distributed to modules via template syntax.
| module | string || The module's name also serves as its identifier and must be unique. | yes |
58
+
<<<<<<< HEAD
44
59
| 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
60
| 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 |
46
61
| 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 |
47
62
48
63
> [!IMPORTANT]
49
64
> Refer to `with` keys of a module in all-lowercase representation of the module's exported fields.
65
+
=======
66
+
| 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. | no |
67
+
| args |[]string | nil | Arguments for non-interactive modules. Can contain static values or template references like `${arg-name}` to command-level args. | no |
68
+
| 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 |
69
+
70
+
> [!IMPORTANT]
71
+
> Refer to option keys of a module in all-lowercase representation of the modules exported fields.
0 commit comments