-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmake_docs.nu
71 lines (58 loc) · 2.25 KB
/
make_docs.nu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
let vers = (version).version
for command in ($nu.scope.commands | where is_custom == false && is_extern == false) {
let top = $"---
title: ($command.command)
layout: command
version: ($vers)
---
($command.usage)
"
let sig = ($command.signature | each { |param|
if $param.parameter_type == "positional" {
$"('(')($param.parameter_name)(')')"
} else if $param.parameter_type == "switch" {
$"--($param.parameter_name)"
} else if $param.parameter_type == "named" {
$"--($param.parameter_name)"
} else if $param.parameter_type == "rest" {
$"...($param.parameter_name)"
}
} | str collect " ")
let signature = $"## Signature(char nl)(char nl)```> ($command.command) ($sig)```(char nl)(char nl)"
let params = ($command.signature | each { |param|
if $param.parameter_type == "positional" {
$" - `($param.parameter_name)`: ($param.description)"
} else if $param.parameter_type == "switch" {
$" - `--($param.parameter_name)`: ($param.description)"
} else if $param.parameter_type == "named" {
$" - `--($param.parameter_name) {($param.syntax_shape)}`: ($param.description)"
} else if $param.parameter_type == "rest" {
$" - `...($param.parameter_name)`: ($param.description)"
}
} | str collect (char nl))
let parameters = if ($command.signature | length) > 0 {
$"## Parameters(char nl)(char nl)($params)(char nl)(char nl)"
} else {
""
}
let examples = if ($command.examples | length) > 0 {
let example_top = $"## Examples(char nl)(char nl)"
let $examples = ($command.examples | each { |example|
$"($example.description)
```shell
> ($example.example)
```
"
} | str collect)
$example_top + $examples
} else { "" }
let doc = (
($top + $signature + $parameters + $examples) |
lines |
each {|it| ($it | str trim -r) } |
str collect (char nl)
)
let safe_name = ($command.command | str find-replace '\?' '' | str find-replace ' ' '_')
$doc | save --raw $"./docs/commands/($safe_name).md"
$"./docs/commands/($safe_name).md"
} | length | $"($in) commands written"