2017-02-12 23:02:42 -06:00
|
|
|
function omf.cli.help
|
|
|
|
set -l IFS ''
|
|
|
|
set -l doc_root $OMF_PATH/docs/cli
|
|
|
|
set -l doc $doc_root/omf.adoc
|
|
|
|
|
|
|
|
# If a command was given, find a help document for it.
|
|
|
|
if set -q argv[1]
|
|
|
|
if not set command (omf.command $argv[1])
|
|
|
|
echo (omf::err)"Unknown command: $argv[1]"(omf::off) >&2
|
|
|
|
return $OMF_UNKNOWN_OPT
|
|
|
|
end
|
|
|
|
|
|
|
|
set doc $doc_root/$command.adoc
|
|
|
|
end
|
2016-05-11 19:29:50 +01:00
|
|
|
|
2017-02-12 23:02:42 -06:00
|
|
|
set -l r (set_color normal ^ /dev/null)
|
|
|
|
set -l c (set_color cyan ^ /dev/null)
|
|
|
|
set -l b (set_color --bold ^ /dev/null)
|
|
|
|
set -l u (set_color --underline ^ /dev/null)
|
2016-05-11 19:29:50 +01:00
|
|
|
|
2017-02-12 23:02:42 -06:00
|
|
|
# Format the help document for the terminal.
|
2017-04-27 12:00:06 -05:00
|
|
|
fold -s -w 78 $doc | sed -e "
|
2017-02-12 23:02:42 -06:00
|
|
|
# Strip cross references.
|
|
|
|
s/<<[^,]*,\([^>]*\)>>/\1/g
|
2015-08-29 16:42:34 -03:00
|
|
|
|
2017-02-12 23:02:42 -06:00
|
|
|
# Definition lists.
|
2017-06-26 10:33:41 -05:00
|
|
|
s/^\([^[:space:]].*\)::\(..*\)/\1\2/g
|
|
|
|
s/^\([^[:space:]].*\)::/$b\1$r/g
|
2015-08-29 16:42:34 -03:00
|
|
|
|
2017-02-12 23:02:42 -06:00
|
|
|
# Nice bullets for unordered lists.
|
|
|
|
s/^[*-] /· /g
|
2015-08-29 16:42:34 -03:00
|
|
|
|
2017-02-12 23:02:42 -06:00
|
|
|
# Indent everything left except for headers and the first line.
|
|
|
|
2,\$ s/^[^=]/ &/
|
2015-08-29 16:42:34 -03:00
|
|
|
|
2017-02-12 23:02:42 -06:00
|
|
|
# Headers.
|
|
|
|
s/^==* \(.*\)/$b\1$r/
|
2015-08-29 16:42:34 -03:00
|
|
|
|
2017-04-27 12:00:06 -05:00
|
|
|
# Highlight bold and monospace text.
|
2017-02-12 23:02:42 -06:00
|
|
|
s/\*\*\([^\*]*\)\*\*/$c\1$r/g
|
|
|
|
s/\*\([^\*]*\)\*/$c\1$r/g
|
2017-04-27 12:00:06 -05:00
|
|
|
s/``\([^`]*\)``/$c\1$r/g
|
|
|
|
s/`\([^`]*\)`/$c\1$r/g
|
2016-07-05 22:30:27 -05:00
|
|
|
|
2017-02-12 23:02:42 -06:00
|
|
|
# Style italics as underline.
|
|
|
|
s/__\([^_]*\)__/$u\1$r/g
|
|
|
|
s/_\([^_]*\)_/$u\1$r/g
|
2016-07-05 22:30:27 -05:00
|
|
|
|
2017-02-12 23:02:42 -06:00
|
|
|
# Underline links.
|
2017-06-26 10:33:41 -05:00
|
|
|
s/[[:alnum:]_][[:alnum:]_]*:[^[:space:]][^[:space:]]*/$u&$r/g
|
2016-07-05 22:30:27 -05:00
|
|
|
|
2017-02-12 23:02:42 -06:00
|
|
|
# Underline variable names in angle brackets.
|
|
|
|
s/<[^>]*>/$u&$r/g
|
|
|
|
"
|
2015-08-27 00:20:13 +09:00
|
|
|
end
|