aboutsummaryrefslogtreecommitdiff
path: root/doc/manual/generate-manpage.nix
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2023-04-16 10:44:03 -0400
committerJohn Ericson <John.Ericson@Obsidian.Systems>2023-04-16 10:57:46 -0400
commitba9ae691b6b0d8f6e23a2a9468aef51a75f16cfe (patch)
treeb3568ab2e87c3ec39cf4bf3072bd5801b372ab89 /doc/manual/generate-manpage.nix
parentab228d73db31ba854faca3d6264817551bcfd4c5 (diff)
Add `optionalString` to manual Nix lang utilities
Use it everywhere it could be also.
Diffstat (limited to 'doc/manual/generate-manpage.nix')
-rw-r--r--doc/manual/generate-manpage.nix28
1 files changed, 15 insertions, 13 deletions
diff --git a/doc/manual/generate-manpage.nix b/doc/manual/generate-manpage.nix
index 0b3a23801..d04eecf55 100644
--- a/doc/manual/generate-manpage.nix
+++ b/doc/manual/generate-manpage.nix
@@ -31,19 +31,18 @@ let
showSynopsis = command: args:
let
- showArgument = arg: "*${arg.label}*" + (if arg ? arity then "" else "...");
+ showArgument = arg: "*${arg.label}*" + optionalString (! arg ? arity) "...";
arguments = concatStringsSep " " (map showArgument args);
in ''
`${command}` [*option*...] ${arguments}
'';
- maybeSubcommands = if details ? commands && details.commands != {}
- then ''
+ maybeSubcommands = optionalString (details ? commands && details.commands != {})
+ ''
where *subcommand* is one of the following:
${subcommands}
- ''
- else "";
+ '';
subcommands = if length categories > 1
then listCategories
@@ -65,12 +64,11 @@ let
* [`${command} ${name}`](./${appendName filename name}.md) - ${subcmd.description}
'';
- maybeDocumentation =
- if details ? doc
- then replaceStrings ["@stores@"] [storeDocs] details.doc
- else "";
+ maybeDocumentation = optionalString
+ (details ? doc)
+ (replaceStrings ["@stores@"] [storeDocs] details.doc);
- maybeOptions = if details.flags == {} then "" else ''
+ maybeOptions = optionalString (details.flags != {}) ''
# Options
${showOptions details.flags toplevel.flags}
@@ -80,15 +78,19 @@ let
let
allOptions = options // commonOptions;
showCategory = cat: ''
- ${if cat != "" then "**${cat}:**" else ""}
+ ${optionalString (cat != "") "**${cat}:**"}
${listOptions (filterAttrs (n: v: v.category == cat) allOptions)}
'';
listOptions = opts: concatStringsSep "\n" (attrValues (mapAttrs showOption opts));
showOption = name: option:
let
- shortName = if option ? shortName then "/ `-${option.shortName}`" else "";
- labels = if option ? labels then (concatStringsSep " " (map (s: "*${s}*") option.labels)) else "";
+ shortName = optionalString
+ (option ? shortName)
+ ("/ `-${option.shortName}`");
+ labels = optionalString
+ (option ? labels)
+ (concatStringsSep " " (map (s: "*${s}*") option.labels));
in trim ''
- `--${name}` ${shortName} ${labels}