2020-08-17 19:33:18 +02:00
|
|
|
def show_flags:
|
2020-08-18 15:15:35 +02:00
|
|
|
.flags
|
|
|
|
| map_values(select(.category != "config"))
|
|
|
|
| to_entries
|
|
|
|
| map(
|
|
|
|
" - `--" + .key + "`"
|
|
|
|
+ (if .value.shortName then " / `" + .value.shortName + "`" else "" end)
|
|
|
|
+ (if .value.labels then " " + (.value.labels | map("*" + . + "*") | join(" ")) else "" end)
|
|
|
|
+ " \n"
|
|
|
|
+ " " + .value.description + "\n\n")
|
|
|
|
| join("")
|
|
|
|
;
|
2020-08-17 19:33:18 +02:00
|
|
|
|
|
|
|
def show_synopsis:
|
2020-08-20 12:21:46 +02:00
|
|
|
"`" + .command + "` [*flags*...] " + (.args | map("*" + .label + "*" + (if has("arity") then "" else "..." end)) | join(" ")) + "\n\n"
|
2020-08-18 15:15:35 +02:00
|
|
|
;
|
2020-08-17 19:33:18 +02:00
|
|
|
|
2020-08-18 15:15:35 +02:00
|
|
|
def show_command:
|
|
|
|
. as $top |
|
|
|
|
.section + " Name\n\n"
|
|
|
|
+ "`" + .command + "` - " + .def.description + "\n\n"
|
|
|
|
+ .section + " Synopsis\n\n"
|
|
|
|
+ ({"command": .command, "args": .def.args} | show_synopsis)
|
2020-08-20 12:21:46 +02:00
|
|
|
+ (if .def | has("doc")
|
|
|
|
then .section + " Description\n\n" + .def.doc + "\n\n"
|
|
|
|
else ""
|
|
|
|
end)
|
2020-08-18 15:15:35 +02:00
|
|
|
+ (if (.def.flags | length) > 0 then
|
|
|
|
.section + " Flags\n\n"
|
|
|
|
+ (.def | show_flags)
|
|
|
|
else "" end)
|
|
|
|
+ (if (.def.examples | length) > 0 then
|
|
|
|
.section + " Examples\n\n"
|
|
|
|
+ (.def.examples | map(.description + "\n\n```console\n" + .command + "\n```\n" ) | join("\n"))
|
|
|
|
+ "\n"
|
|
|
|
else "" end)
|
|
|
|
+ (if .def.commands then .def.commands | to_entries | map(
|
|
|
|
"# Subcommand `" + ($top.command + " " + .key) + "`\n\n"
|
|
|
|
+ ({"command": ($top.command + " " + .key), "section": "##", "def": .value} | show_command)
|
|
|
|
) | join("") else "" end)
|
|
|
|
;
|
2020-08-17 19:33:18 +02:00
|
|
|
|
2020-08-18 15:15:35 +02:00
|
|
|
"Title: nix\n\n"
|
|
|
|
+ ({"command": "nix", "section": "#", "def": .} | show_command)
|