File tree Expand file tree Collapse file tree 1 file changed +14
-13
lines changed Expand file tree Collapse file tree 1 file changed +14
-13
lines changed Original file line number Diff line number Diff line change 1- { lib } :
2- # root is the absolute path to the directory with .lbf files.
3- # Example
4- # ~~~~~~
1+ # Provides a nix function which recursively lists all lbf modules in a
2+ # directory.
3+ #
4+ # Type: { lib : attr } -> path -> [string]
5+ #
6+ # Example:
57# ```nix
68# let
79# lbfListModules = pkgs.callPackage (import ./lbf-list-modules.nix) {};
2123# └── MySchema.lbf
2224# ```
2325
26+ { lib } :
27+ # root is the absolute path to the directory with .lbf files.
2428root :
25- # INVARIANT:
26- # - dir == dotPrefix except dotPrefix doesn't contain the prefix root, and
27- # dotPrefix has all `/`s replaced with a singular `.`
28- # - `dotPrefix` always contains the dot at the end if it needs to be there
2929let
30+ # Given `<name>.lbf`, this returns `<name>` returning `null` otherwise.
31+ # Type: matchLbfFile :: string -> string | null
3032 matchLbfFile = name :
3133 let matches = builtins . match ''(.*)\.lbf$'' name ;
3234 in if matches == null
3335 then null
3436 else builtins . elemAt matches 0 ;
3537
36- go = dir : dotPrefix :
38+ go = dir :
3739 builtins . concatLists
3840 ( lib . mapAttrsToList
3941 ( name : value :
4042 if value == "directory"
41- then go "${ dir } /${ name } " "${ dotPrefix } ${ name } ."
42-
43+ then builtins . map ( suffix : "${ name } .${ suffix } " ) ( go "${ dir } /${ name } " )
4344 else if value == "regular"
4445 then
4546 # Is this an lbf file?
4647 let lbfFileMatch = matchLbfFile name ;
4748 in if lbfFileMatch != null
48- then [ " ${ dotPrefix } ${ lbfFileMatch } " ]
49+ then [ lbfFileMatch ]
4950 else [ ]
5051 else
5152 builtins . trace ''warning: `${ name } ` has file type `${ value } ` which is not a regular file nor directory''
5455 ( builtins . readDir dir )
5556 ) ;
5657in
57- go root ""
58+ go root
You can’t perform that action at this time.
0 commit comments