32
32
33
33
commandInfo = fromJSON commandDump ;
34
34
35
- showCommand = { command , details , filename , toplevel } :
35
+ showCommand =
36
+ {
37
+ command ,
38
+ details ,
39
+ filename ,
40
+ toplevel ,
41
+ } :
36
42
let
37
43
38
44
result = ''
56
62
${ maybeOptions }
57
63
'' ;
58
64
59
- showSynopsis = command : args :
65
+ showSynopsis =
66
+ command : args :
60
67
let
61
- showArgument = arg : "*${ arg . label } *" + optionalString ( ! arg ? arity ) "..." ;
68
+ showArgument = arg : "*${ arg . label } *" + optionalString ( ! arg ? arity ) "..." ;
62
69
arguments = concatStringsSep " " ( map showArgument args ) ;
63
- in ''
70
+ in
71
+ ''
64
72
`${ command } ` [*option*...] ${ arguments }
65
73
'' ;
66
74
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:
70
77
71
- ${ subcommands }
72
- '' ;
78
+ ${ subcommands }
79
+ '' ;
73
80
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 ;
77
82
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
+ ) ;
79
86
80
87
listCategories = concatStrings ( map showCategory categories ) ;
81
88
99
106
100
107
${ allStores }
101
108
'' ;
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 ;
106
114
storesOverview =
107
115
let
108
- showEntry = store :
109
- "- [${ store . name } ](#${ store . slug } )" ;
116
+ showEntry = store : "- [${ store . name } ](#${ store . slug } )" ;
110
117
in
111
118
concatStringsSep "\n " ( map showEntry storesList ) + "\n " ;
112
119
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
+ ) ;
115
126
storesList = showStoreDocs {
116
127
storeInfo = commandInfo . stores ;
117
128
inherit inlineHTML ;
118
129
} ;
119
- hasInfix = infix : content :
130
+ hasInfix =
131
+ infix : content :
120
132
builtins . stringLength content != builtins . stringLength ( replaceStrings [ infix ] [ "" ] content ) ;
121
133
in
122
134
optionalString ( details ? doc ) (
123
135
# 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
127
137
) ;
128
138
129
139
maybeOptions =
130
140
let
131
- allVisibleOptions = filterAttrs
132
- ( _ : o : ! o . hiddenCategory )
133
- ( details . flags // toplevel . flags ) ;
141
+ allVisibleOptions = filterAttrs ( _ : o : ! o . hiddenCategory ) ( details . flags // toplevel . flags ) ;
134
142
in
135
143
optionalString ( allVisibleOptions != { } ) ''
136
144
# Options
@@ -142,55 +150,73 @@ let
142
150
> See [`man nix.conf`](@docroot@/command-ref/conf-file.md#command-line-flags) for overriding configuration settings with command line flags.
143
151
'' ;
144
152
145
- showOptions = inlineHTML : allOptions :
153
+ showOptions =
154
+ inlineHTML : allOptions :
146
155
let
147
156
showCategory = cat : opts : ''
148
157
${ optionalString ( cat != "" ) "## ${ cat } " }
149
158
150
159
${ concatStringsSep "\n " ( attrValues ( mapAttrs showOption opts ) ) }
151
160
'' ;
152
- showOption = name : option :
161
+ showOption =
162
+ name : option :
153
163
let
154
164
result = trim ''
155
165
- ${ item }
156
166
157
167
${ option . description }
158
168
'' ;
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 ;
177
187
178
188
appendName = filename : name : ( if filename == "nix" then "nix3" else filename ) + "-" + name ;
179
189
180
- processCommand = { command , details , filename , toplevel } :
190
+ processCommand =
191
+ {
192
+ command ,
193
+ details ,
194
+ filename ,
195
+ toplevel ,
196
+ } :
181
197
let
182
198
cmd = {
183
199
inherit command ;
184
200
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
+ } ;
192
209
} ;
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 { } ) ;
194
220
195
221
manpages = processCommand {
196
222
command = "nix" ;
199
225
toplevel = commandInfo . args ;
200
226
} ;
201
227
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 " ;
206
233
207
- in ( listToAttrs manpages ) // { "SUMMARY.md" = tableOfContents ; }
234
+ in
235
+ ( listToAttrs manpages ) // { "SUMMARY.md" = tableOfContents ; }
0 commit comments