Skip to content

Commit 94baa8e

Browse files
committed
Add Help page with generated markdown output for all commands and topics
1 parent b21c6ca commit 94baa8e

File tree

4 files changed

+142
-0
lines changed

4 files changed

+142
-0
lines changed

_config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ header_pages:
4646
- crates.md
4747
- search.html
4848
- docs/index.md
49+
- docs/index-alr.md
4950

5051
# Devlopr
5152
author_logo: profile.png

alr-help-md.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/bash
2+
3+
# Safer shell
4+
set -o nounset
5+
set -o errexit
6+
7+
alr_version=$(alr --no-tty version | grep "alr version" | cut -d: -f2 | tr -d '[:blank:]')
8+
alire_lib_version=$(alr --no-tty version | grep "libalire version" | cut -d: -f2 | tr -d '[:blank:]')
9+
10+
# Print a horizontal rule and Alire versions
11+
function print_version () {
12+
echo
13+
echo "---------------------------------------------------------"
14+
echo "Alr \`${alr_version}\`."
15+
echo "Alire Library \`${alire_lib_version}\`."
16+
echo
17+
}
18+
19+
# $1 : page title
20+
function print_header () {
21+
echo "---"
22+
echo "title: $1"
23+
echo "layout: page"
24+
echo "---"
25+
}
26+
27+
topic_list=$(alr help | awk '/^ +[a-z]+/ {if ($1 !~ "alr") {print $1}}')
28+
29+
mkdir -p man
30+
31+
# Make a page from each help topic
32+
for topic in $topic_list; do
33+
if alr --markdown help $topic > /dev/null 2>&1 ; then
34+
echo "Info: generating alr-${topic}.md"
35+
{
36+
print_header "alr $topic"
37+
alr --markdown help $topic
38+
print_version
39+
} > alr-${topic}.md
40+
else
41+
echo "Warning: skipping \"${topic}\"; it might be an invalid topic" >&2
42+
fi
43+
done
44+
45+
# Make an index from the help subcommand.
46+
{
47+
print_header "alr help"
48+
# For every line starting by possible whitespace and a code word (topic),
49+
# if the word matches an existing alire help page then
50+
# replace word by a link to the page.
51+
# For any other line, print as is.
52+
alr --markdown help | awk '
53+
/^ +`[a-z]+`/ {
54+
topic=gensub(/`/, "", "g", $1)
55+
if (system("test -f alr-" topic ".md") == 0) {
56+
sub(/`[a-z]+`/, "[`" topic "`](alr-" topic ")")
57+
}
58+
}
59+
{
60+
print
61+
}'
62+
print_version
63+
} > alr-help.md

docs/index-alr.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
---
2+
title: Help
3+
description: "alr manual pages"
4+
layout: default
5+
---
6+
<div class="card">
7+
<style>
8+
/* Create two equal columns that floats next to each other */
9+
.doc_toc {
10+
float: left;
11+
width: 15em;
12+
}
13+
14+
.doc_content {
15+
float: left;
16+
width: calc(100% - 15em);
17+
}
18+
19+
/* Clear floats after the columns */
20+
.doc_row:after {
21+
content: "";
22+
display: table;
23+
clear: both;
24+
}
25+
26+
/* Responsive layout - makes the two columns stack on top of each other instead
27+
of next to each other */
28+
29+
@media screen and (max-width: 60em) {
30+
.doc_toc {
31+
width: 100%;
32+
}
33+
.doc_content {
34+
width: 100%;
35+
}
36+
}
37+
38+
/* Table-of-content style */
39+
#markdown-toc {
40+
padding-left: 1em;
41+
font-size: smaller;
42+
}
43+
#markdown-toc ul {
44+
padding-left: 1em;
45+
}
46+
47+
48+
</style>
49+
<div class="doc_row">
50+
<div class="doc_toc">
51+
<div markdown="1">
52+
53+
* Do not remove this line (it will not be displayed)
54+
{:toc}
55+
56+
</div>
57+
<small style="color:#808080">
58+
This help documentation has been generated from the builtin `alr` help
59+
messages. Don't hesitate to suggest fix(es) and/or improvement(s) in
60+
the <a href="https://github.com/alire-project/alire/src/alr">GitHub
61+
repository.</a>
62+
</small>
63+
</div>
64+
<div class="doc_content" markdown="1">
65+
66+
<!-- All the empty lines below, as well as the absence of indentation, seem to
67+
be required for a correct parsing of the markdown files -->
68+
69+
{% include_relative alr.md %}
70+
71+
</div>
72+
</div>
73+
</div>

update-gh-pages.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ cp alire/doc/* docs/
6565
# Append the built-ins config doc generated from the tool
6666
alr --no-tty config --builtins-doc >> docs/configuration.md
6767

68+
# Add the `alr` help page
69+
# Substitution is needed because <placeholder> from messages are interpreted by Jekyll
70+
# TODO This can be removed if all these <placeholders> are quoted as `code`.
71+
alr dev --markdown-help | sed 's/</`<`/g; s/>/`>`/g' > docs/alr.md
72+
6873
# Cleanup alire repo
6974
rm -rf alire/
7075

0 commit comments

Comments
 (0)