3232
3333 commandInfo = fromJSON commandDump ;
3434
35- showCommand = { command , details , filename , toplevel } :
35+ showCommand =
36+ {
37+ command ,
38+ details ,
39+ filename ,
40+ toplevel ,
41+ } :
3642 let
3743
3844 result = ''
5662 ${ maybeOptions }
5763 '' ;
5864
59- showSynopsis = command : args :
65+ showSynopsis =
66+ command : args :
6067 let
61- showArgument = arg : "*${ arg . label } *" + optionalString ( ! arg ? arity ) "..." ;
68+ showArgument = arg : "*${ arg . label } *" + optionalString ( ! arg ? arity ) "..." ;
6269 arguments = concatStringsSep " " ( map showArgument args ) ;
63- in ''
70+ in
71+ ''
6472 `${ command } ` [*option*...] ${ arguments }
6573 '' ;
6674
67- maybeSubcommands = optionalString ( details ? commands && details . commands != { } )
68- ''
69- where *subcommand* is one of the following:
75+ maybeSubcommands = optionalString ( details ? commands && details . commands != { } ) ''
76+ where *subcommand* is one of the following:
7077
71- ${ subcommands }
72- '' ;
78+ ${ subcommands }
79+ '' ;
7380
74- subcommands = if length categories > 1
75- then listCategories
76- else listSubcommands details . commands ;
81+ subcommands = if length categories > 1 then listCategories else listSubcommands details . commands ;
7782
78- categories = sort ( x : y : x . id < y . id ) ( unique ( map ( cmd : cmd . category ) ( attrValues details . commands ) ) ) ;
83+ categories = sort ( x : y : x . id < y . id ) (
84+ unique ( map ( cmd : cmd . category ) ( attrValues details . commands ) )
85+ ) ;
7986
8087 listCategories = concatStrings ( map showCategory categories ) ;
8188
99106
100107 ${ allStores }
101108 '' ;
102- index = replaceStrings
103- [ "@store-types@" "./local-store.md" "./local-daemon-store.md" ]
104- [ storesOverview "#local-store" "#local-daemon-store" ]
105- details . doc ;
109+ index =
110+ replaceStrings
111+ [ "@store-types@" "./local-store.md" "./local-daemon-store.md" ]
112+ [ storesOverview "#local-store" "#local-daemon-store" ]
113+ details . doc ;
106114 storesOverview =
107115 let
108- showEntry = store :
109- "- [${ store . name } ](#${ store . slug } )" ;
116+ showEntry = store : "- [${ store . name } ](#${ store . slug } )" ;
110117 in
111118 concatStringsSep "\n " ( map showEntry storesList ) + "\n " ;
112119 allStores = concatStringsSep "\n " ( attrValues storePages ) ;
113- storePages = listToAttrs
114- ( map ( s : { name = s . filename ; value = s . page ; } ) storesList ) ;
120+ storePages = listToAttrs (
121+ map ( s : {
122+ name = s . filename ;
123+ value = s . page ;
124+ } ) storesList
125+ ) ;
115126 storesList = showStoreDocs {
116127 storeInfo = commandInfo . stores ;
117128 inherit inlineHTML ;
118129 } ;
119- hasInfix = infix : content :
130+ hasInfix =
131+ infix : content :
120132 builtins . stringLength content != builtins . stringLength ( replaceStrings [ infix ] [ "" ] content ) ;
121133 in
122134 optionalString ( details ? doc ) (
123135 # An alternate implementation with builtins.match stack overflowed on some systems.
124- if hasInfix "@store-types@" details . doc
125- then help-stores
126- else details . doc
136+ if hasInfix "@store-types@" details . doc then help-stores else details . doc
127137 ) ;
128138
129139 maybeOptions =
130140 let
131- allVisibleOptions = filterAttrs
132- ( _ : o : ! o . hiddenCategory )
133- ( details . flags // toplevel . flags ) ;
141+ allVisibleOptions = filterAttrs ( _ : o : ! o . hiddenCategory ) ( details . flags // toplevel . flags ) ;
134142 in
135143 optionalString ( allVisibleOptions != { } ) ''
136144 # Options
@@ -142,55 +150,73 @@ let
142150 > See [`man nix.conf`](@docroot@/command-ref/conf-file.md#command-line-flags) for overriding configuration settings with command line flags.
143151 '' ;
144152
145- showOptions = inlineHTML : allOptions :
153+ showOptions =
154+ inlineHTML : allOptions :
146155 let
147156 showCategory = cat : opts : ''
148157 ${ optionalString ( cat != "" ) "## ${ cat } " }
149158
150159 ${ concatStringsSep "\n " ( attrValues ( mapAttrs showOption opts ) ) }
151160 '' ;
152- showOption = name : option :
161+ showOption =
162+ name : option :
153163 let
154164 result = trim ''
155165 - ${ item }
156166
157167 ${ option . description }
158168 '' ;
159- item = if inlineHTML
160- then ''<span id="opt- ${ name } ">[`-- ${ name } `](#opt- ${ name } )</span> ${ shortName } ${ labels } ''
161- else " `--${ name } ` ${ shortName } ${ labels } " ;
162- shortName = optionalString
163- ( option ? shortName )
164- ( "/ `-${ option . shortName } `" ) ;
165- labels = optionalString
166- ( option ? labels )
167- ( concatStringsSep " " ( map ( s : "* ${ s } *" ) option . labels ) ) ;
168- in result ;
169- categories = mapAttrs
170- # Convert each group from a list of key-value pairs back to an attrset
171- ( _ : listToAttrs )
172- ( groupBy
173- ( cmd : cmd . value . category )
174- ( attrsToList allOptions ) ) ;
175- in concatStrings ( attrValues ( mapAttrs showCategory categories ) ) ;
176- in squash result ;
169+ item =
170+ if inlineHTML then
171+ ''<span id="opt- ${ name } ">[ `--${ name } `](#opt- ${ name } )</span> ${ shortName } ${ labels } ''
172+ else
173+ "`-- ${ name } ` ${ shortName } ${ labels } " ;
174+ shortName = optionalString ( option ? shortName ) ( "/ `-${ option . shortName } `" ) ;
175+ labels = optionalString ( option ? labels ) ( concatStringsSep " " ( map ( s : "* ${ s } *" ) option . labels ) ) ;
176+ in
177+ result ;
178+ categories =
179+ mapAttrs
180+ # Convert each group from a list of key-value pairs back to an attrset
181+ ( _ : listToAttrs )
182+ ( groupBy ( cmd : cmd . value . category ) ( attrsToList allOptions ) ) ;
183+ in
184+ concatStrings ( attrValues ( mapAttrs showCategory categories ) ) ;
185+ in
186+ squash result ;
177187
178188 appendName = filename : name : ( if filename == "nix" then "nix3" else filename ) + "-" + name ;
179189
180- processCommand = { command , details , filename , toplevel } :
190+ processCommand =
191+ {
192+ command ,
193+ details ,
194+ filename ,
195+ toplevel ,
196+ } :
181197 let
182198 cmd = {
183199 inherit command ;
184200 name = filename + ".md" ;
185- value = showCommand { inherit command details filename toplevel ; } ;
186- } ;
187- subcommand = subCmd : processCommand {
188- command = command + " " + subCmd ;
189- details = details . commands . ${ subCmd } ;
190- filename = appendName filename subCmd ;
191- inherit toplevel ;
201+ value = showCommand {
202+ inherit
203+ command
204+ details
205+ filename
206+ toplevel
207+ ;
208+ } ;
192209 } ;
193- in [ cmd ] ++ concatMap subcommand ( attrNames details . commands or { } ) ;
210+ subcommand =
211+ subCmd :
212+ processCommand {
213+ command = command + " " + subCmd ;
214+ details = details . commands . ${ subCmd } ;
215+ filename = appendName filename subCmd ;
216+ inherit toplevel ;
217+ } ;
218+ in
219+ [ cmd ] ++ concatMap subcommand ( attrNames details . commands or { } ) ;
194220
195221 manpages = processCommand {
196222 command = "nix" ;
199225 toplevel = commandInfo . args ;
200226 } ;
201227
202- tableOfContents = let
203- showEntry = page :
204- " - [${ page . command } ](command-ref/new-cli/${ page . name } )" ;
205- in concatStringsSep "\n " ( map showEntry manpages ) + "\n " ;
228+ tableOfContents =
229+ let
230+ showEntry = page : " - [${ page . command } ](command-ref/new-cli/${ page . name } )" ;
231+ in
232+ concatStringsSep "\n " ( map showEntry manpages ) + "\n " ;
206233
207- in ( listToAttrs manpages ) // { "SUMMARY.md" = tableOfContents ; }
234+ in
235+ ( listToAttrs manpages ) // { "SUMMARY.md" = tableOfContents ; }
0 commit comments