From bd908307c4fe86adba5409b3a205c36aa1f130f9 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Sat, 12 Aug 2023 21:12:57 +0100 Subject: [PATCH] print module pathname if it contains services so that the user knows what to add to their imports --- doc/parse-options.fnl | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/doc/parse-options.fnl b/doc/parse-options.fnl index 076c43d..56d305a 100644 --- a/doc/parse-options.fnl +++ b/doc/parse-options.fnl @@ -18,6 +18,13 @@ :until (not (= (string.sub l 1 2) "##"))] (.. (or lines "") (string.gsub l "^## *" "") "\n")))))) +(fn relative-pathname [pathname] + (let [pathname + (if (string.match pathname ".nix$") + pathname + (.. pathname "/default.nix"))] + (pick-values 1 (string.gsub pathname "^/nix/store/[^/]+/" "modules/")))) + (fn strip-newlines [text] (-> text (string.gsub "\n([^\n])" " %1") @@ -108,10 +115,14 @@ (tset modules path e)))) (tset modules "lib/modules.nix" nil) (let [modules (sort-modules modules)] - (each [_ {: name : module} (ipairs modules)] + (each [_ {: name : module : service?} (ipairs modules)] (let [options (sort-options module)] - (print (or (read-preamble name) (headline name))) - (each [_ o (ipairs options)] - (if (is-service? o) - (print-service o) - (print-option o))))))) + (when (> (# options) 0) + (print (or (read-preamble name) (headline name))) + (when service? + (print "**path** " (.. ":file:`" (relative-pathname name) "`"))) + (print) + (each [_ o (ipairs options)] + (if (is-service? o) + (print-service o) + (print-option o))))))))