lib.sources.sourceFilesBySuffices: Improve doc

This commit is contained in:
Robert Hensing 2021-03-28 21:49:20 +02:00
parent d14be76615
commit 970273023a

View file

@ -104,14 +104,26 @@ let
inherit src; inherit src;
}; };
# Get all files ending with the specified suffices from the given /*
# directory or its descendants. E.g. `sourceFilesBySuffices ./dir Get all files ending with the specified suffices from the given
# [".xml" ".c"]'. source directory or its descendants, omitting files that do not match
sourceFilesBySuffices = path: exts: any suffix. The result of the example below will include files like
`./dir/module.c` and `./dir/subdir/doc.xml` if present.
Type: sourceLike -> [String] -> Source
Example:
sourceFilesBySuffices ./. [ ".xml" ".c" ]
*/
sourceFilesBySuffices =
# Path or source containing the files to be returned
src:
# A list of file suffix strings
exts:
let filter = name: type: let filter = name: type:
let base = baseNameOf (toString name); let base = baseNameOf (toString name);
in type == "directory" || lib.any (ext: lib.hasSuffix ext base) exts; in type == "directory" || lib.any (ext: lib.hasSuffix ext base) exts;
in cleanSourceWith { inherit filter; src = path; }; in cleanSourceWith { inherit filter src; };
pathIsGitRepo = path: (tryEval (commitIdFromGitRepo path)).success; pathIsGitRepo = path: (tryEval (commitIdFromGitRepo path)).success;