-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgen-docs
executable file
·119 lines (100 loc) · 2.21 KB
/
gen-docs
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env raku
use lib 'lib';
use Termie::Commands;
sub to-url(Str $file,Int $line) {
'https://github.com/bduggan/termie/blob/master/'
~ $file
~ '#L'
~ $line;
}
sub esc($str) {
return $str if $str.?escaped.html;
$str.trans( [ '<' , '>' , '&' ] =>
[ '<', '>', '&' ])
}
multi tag($name,$content) {
tag($name,{},$content);
}
multi tag($name,%attrs={},$content='') {
return
'<' ~ $name
~ join ' ', %attrs.kv.map({qq[ $^key="$^value"]})
~ '>'
~ $content
~ '</'
~ $name
~ '>';
}
sub h2($str) {
return "## $str" unless $*html;
tag('h2',$str);
}
sub h3($str) {
return "### $str" unless $*html;
tag('h3',$str);
}
sub dl-start {
return '```' unless $*html;
return '<dl>';
}
sub dl-end {
return '```' unless $*html;
return '</dl>';
}
sub hr {
return "---" unless $*html;
return '<hr>';
}
sub rel-file($f) {
$f.IO.relative('.').subst(/' (' [ \w | ':' ]+ ')' $/,'');
}
sub show-command($h) {
if !$*html {
say $h<text>;
return;
}
with $h<file> -> $f {
say tag('dt',
~tag('a',{href => to-url(rel-file($f), +$h<line>)}, '\\' ~ esc($h<cmd>))
);
say tag('dd', esc($h<desc>));
} else {
say tag('dt', '\\' ~ esc($h<cmd>));
say tag('dd', esc($h<desc>));
}
}
unit sub MAIN(Bool :$*html, Str :$cmd = '');
my @help = Termie::Commands.new.generate-help($cmd);
my %c = @help.classify: { $^line.<text> ~~ / ^^ \s* '\script '/ ?? 'script' !! 'interactive' };
say h2("Currently supported commands");
say "";
say h2("Interactive");
say "";
say "In interactive mode these commands are supported:";
say "";
say dl-start;
for %c<interactive>.sort(*.<text>) -> $h {
unless $h<cmd> {
note "missing something " ~ $h.raku;
next;
}
next if $cmd && $h<cmd> !~~ /$cmd/;
show-command($h);
}
say dl-end;
say h3("Scripts");
say "";
say "In scripting mode, these additional commands are supported:";
say "";
say dl-start;
for %c<script>.sort(*.<text>) -> $h {
next if $cmd;
$h<text> .= subst(/script \s* /,'');
$h<cmd> .= subst(/script \s* /,'');
show-command($h);
}
say dl-end;
say "";
say hr;
say "";
say "For more verbose descriptions of these commands, please refer to the source code!";