Skip to content

Commit

Permalink
Add optionalString to manual Nix lang utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
Ericson2314 committed Apr 16, 2023
1 parent ab228d7 commit c3d4b57
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
24 changes: 13 additions & 11 deletions doc/manual/generate-manpage.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@ let
`${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
Expand All @@ -65,10 +64,9 @@ 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 ''
# Options
Expand All @@ -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}
Expand Down
2 changes: 2 additions & 0 deletions doc/manual/utils.nix
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ rec {
filterAttrs = pred: set:
listToAttrs (concatMap (name: let v = set.${name}; in if pred name v then [(nameValuePair name v)] else []) (attrNames set));

optionalString = cond: string: if cond then string else "";

showSetting = { useAnchors }: name: { description, documentDefault, defaultValue, aliases, value }:
let
result = squash ''
Expand Down

0 comments on commit c3d4b57

Please sign in to comment.