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
Copy file name to clipboardExpand all lines: README.md
+84-39Lines changed: 84 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,7 +25,7 @@ dub run md -- --help
25
25
26
26
## Features
27
27
28
-
The code block whose language is specified as `d`or `D` will be executed.
28
+
The code block whose language is specified as `d`, `D`, `sh`, or `bash` will be executed.
29
29
30
30
### Combine blocks
31
31
@@ -99,43 +99,81 @@ auto message = "filter test";
99
99
writeln(message);
100
100
```
101
101
102
-
```d name=filter_test2
103
-
import std;
104
-
105
-
auto message2 = "another filter test";
106
-
writeln(message2);
107
-
```
108
-
109
-
#### Multiple names
110
-
111
-
You can assign multiple `name` attributes to a single code block.
112
-
That block will be included in every matching named block.
113
-
114
-
~~~
115
-
```d name=multi_name_test1 name=multi_name_test2
116
-
```
117
-
~~~
118
-
119
-
```
120
-
dub run md -- README.md --filter=multi_name_test1
121
-
dub run md -- README.md --filter=multi_name_test2
122
-
```
123
-
124
-
```d name=multi_name_test1 name=multi_name_test2
125
-
import std.stdio;
126
-
```
127
-
128
-
```d name=multi_name_test1
129
-
writeln("multi-name test1");
130
-
```
131
-
132
-
```d name=multi_name_test2
133
-
writeln("multi-name test2");
134
-
```
135
-
136
-
137
-
138
-
### Scoped block
102
+
```d name=filter_test2
103
+
import std;
104
+
105
+
auto message2 = "another filter test";
106
+
writeln(message2);
107
+
```
108
+
109
+
#### Multiple names
110
+
111
+
You can assign multiple `name` attributes to a single code block.
112
+
That block will be included in every matching named block.
113
+
114
+
~~~
115
+
```d name=multi_name_test1 name=multi_name_test2
116
+
```
117
+
~~~
118
+
119
+
```
120
+
dub run md -- README.md --filter=multi_name_test1
121
+
dub run md -- README.md --filter=multi_name_test2
122
+
```
123
+
124
+
```d name=multi_name_test1 name=multi_name_test2
125
+
import std.stdio;
126
+
```
127
+
128
+
```d name=multi_name_test1
129
+
writeln("multi-name test1");
130
+
```
131
+
132
+
```d name=multi_name_test2
133
+
writeln("multi-name test2");
134
+
```
135
+
136
+
### Shell blocks
137
+
138
+
`sh` and `bash` blocks are executed with the same `name` and `--filter` rules as D blocks.
139
+
The default name is `main`, and a single block can have multiple names.
140
+
141
+
~~~
142
+
```sh name=shell_sample
143
+
```
144
+
~~~
145
+
146
+
```
147
+
dub run md -- README.md --filter=shell_sample
148
+
dub run md -- README.md --filter=bash_sample
149
+
```
150
+
151
+
```sh name=shell_sample
152
+
shared_shell="from-sh"
153
+
echo"sh:${shared_shell}"
154
+
```
155
+
156
+
```bash name=shell_sample name=bash_sample
157
+
shared_bash="from-bash"
158
+
```
159
+
160
+
```bash name=bash_sample
161
+
parts=("A""B")
162
+
echo"bash:${shared_bash}:${parts[1]}"
163
+
```
164
+
165
+
Execution details:
166
+
1.`sh` blocks run as `sh -eu <temp_script_path>`
167
+
2.`bash` blocks run as `bash -eu -o pipefail <temp_script_path>`
168
+
3. Scripts are executed from the current working directory where `md` is launched
169
+
4. Non-zero exit code is treated as an error
170
+
5.`--build`, `--compiler`, `--arch`, `--dependency`, and `--dubsdl` apply only to D execution
171
+
6.`--buildOnly` skips shell script execution
172
+
7.`--show-lang` prints language-aware begin/end labels as `<language>:<block-name>` (default keeps the original label format)
173
+
174
+
175
+
176
+
### Scoped block
139
177
140
178
To make a single block of code run independently without being combined with other blocks, give it the attribute `single`.
141
179
@@ -218,7 +256,14 @@ void main()
218
256
219
257
### How it works
220
258
221
-
Create a `.md` directory in the temp directory, generate the source in dub single file format, and run it with a command like `dub run --single md_xxx.md`.
259
+
Create a `.md` directory in the temp directory and generate temporary files for each execution unit.
260
+
261
+
Execution model by language:
262
+
1. D: generate a dub single-file source and run it with `dub run --single md_xxx.d` (or `dub build --single ...` with `--buildOnly`)
263
+
2. sh: generate a script file and run `sh -eu md_xxx.sh`
264
+
3. bash: generate a script file and run `bash -eu -o pipefail md_xxx.sh`
265
+
266
+
Named blocks are combined by `language + name` before execution, and `--filter` narrows the target names.
222
267
223
268
It also automatically adds the following comment to the beginning of the source to achieve default package references.
0 commit comments