Skip to content

Commit 15ac42b

Browse files
author
jared
committed
Improved documentation for extras/lbf-nix/lbf-list-modules.nix, and
cleaned up the DFS to build the module names bottom up.
1 parent fb6d7c0 commit 15ac42b

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed
Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
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) {};
@@ -21,31 +23,30 @@
2123
# └── MySchema.lbf
2224
# ```
2325

26+
{ lib }:
27+
# root is the absolute path to the directory with .lbf files.
2428
root:
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
2929
let
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''
@@ -54,4 +55,4 @@ let
5455
(builtins.readDir dir)
5556
);
5657
in
57-
go root ""
58+
go root

0 commit comments

Comments
 (0)