Improve nix.1 manpage generator

This commit is contained in:
Eelco Dolstra 2020-08-18 15:15:35 +02:00
parent 6f19c776db
commit 069340179e
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
2 changed files with 40 additions and 37 deletions

View file

@ -1,42 +1,40 @@
def show_flags: def show_flags:
.flags
.flags | map_values(select(.category != "config"))
| map_values(select(.category != "config")) | to_entries
| to_entries | map(
| map(
" - `--" + .key + "`" " - `--" + .key + "`"
+ (if .value.shortName then " / `" + .value.shortName + "`" else "" end) + (if .value.shortName then " / `" + .value.shortName + "`" else "" end)
+ (if .value.labels then " " + (.value.labels | map("*" + . + "*") | join(" ")) else "" end) + (if .value.labels then " " + (.value.labels | map("*" + . + "*") | join(" ")) else "" end)
+ " \n" + " \n"
+ " " + .value.description + "\n\n") + " " + .value.description + "\n\n")
| join("") | join("")
; ;
def show_synopsis: def show_synopsis:
"`" + .command + "` " + (.args | map("*" + .label + "*" + (if has("arity") then "" else "..." end)) | join(" ")) + "\n\n"
;
"`" + .command + "` " + (.args | map("*" + .label + "*" + (if has("arity") then "" else "..." end)) | join(" ")) + "\n" def show_command:
. as $top |
; .section + " Name\n\n"
+ "`" + .command + "` - " + .def.description + "\n\n"
"# Synopsis\n\n" + .section + " Synopsis\n\n"
+ ({"command": "nix", "args": .args} | show_synopsis) + ({"command": .command, "args": .def.args} | show_synopsis)
+ "\n" + (if (.def.flags | length) > 0 then
+ "# Common flags\n\n" .section + " Flags\n\n"
+ show_flags + (.def | show_flags)
+ (.commands | to_entries | map(
"# Operation `" + .key + "`\n\n"
+ "## Synopsis\n\n"
+ ({"command": ("nix " + .key), "args": .value.args} | show_synopsis)
+ "\n"
+ "## Description\n\n"
+ .value.description + "\n\n"
+ (if (.value.flags | length) > 0 then
"## Flags\n\n"
+ (.value | show_flags)
else "" end) else "" end)
+ (if (.value.examples | length) > 0 then + (if (.def.examples | length) > 0 then
"## Examples\n\n" .section + " Examples\n\n"
+ (.value.examples | map("- " + .description + "\n\n ```console\n " + .command + "\n ```\n" ) | join("\n")) + (.def.examples | map(.description + "\n\n```console\n" + .command + "\n```\n" ) | join("\n"))
+ "\n" + "\n"
else "" end) else "" end)
) | join("")) + (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)
;
"Title: nix\n\n"
+ ({"command": "nix", "section": "#", "def": .} | show_command)

View file

@ -142,6 +142,11 @@ struct NixArgs : virtual MultiCommand, virtual MixCommonArgs
printHelp(programName, std::cout); printHelp(programName, std::cout);
throw Exit(); throw Exit();
} }
std::string description() override
{
return "a tool for reproducible and declarative configuration management";
}
}; };
void mainWrapped(int argc, char * * argv) void mainWrapped(int argc, char * * argv)