about summary refs log tree commit diff
path: root/nixos/modules
diff options
context:
space:
mode:
authorChuck <chuck@intelligence.org>2019-09-16 10:01:40 -0700
committerLinus Heckemann <git@sphalerite.org>2019-11-04 15:11:45 +0100
commit56462408700a39bf49d130a862570ebf48b8e17c (patch)
tree471ae6d9a229ede38e83402af4d0756c07f59cdd /nixos/modules
parent4d17d5b31f196416ee4be50b0f7b125966ea210f (diff)
downloadnixlib-56462408700a39bf49d130a862570ebf48b8e17c.tar
nixlib-56462408700a39bf49d130a862570ebf48b8e17c.tar.gz
nixlib-56462408700a39bf49d130a862570ebf48b8e17c.tar.bz2
nixlib-56462408700a39bf49d130a862570ebf48b8e17c.tar.lz
nixlib-56462408700a39bf49d130a862570ebf48b8e17c.tar.xz
nixlib-56462408700a39bf49d130a862570ebf48b8e17c.tar.zst
nixlib-56462408700a39bf49d130a862570ebf48b8e17c.zip
Only print example when there is one
Diffstat (limited to 'nixos/modules')
-rw-r--r--nixos/modules/installer/tools/nixos-option/nixos-option.cc15
1 files changed, 13 insertions, 2 deletions
diff --git a/nixos/modules/installer/tools/nixos-option/nixos-option.cc b/nixos/modules/installer/tools/nixos-option/nixos-option.cc
index 58d66bad1c65..3261b263c2f2 100644
--- a/nixos/modules/installer/tools/nixos-option/nixos-option.cc
+++ b/nixos/modules/installer/tools/nixos-option/nixos-option.cc
@@ -402,6 +402,15 @@ void printAttr(Context & ctx, Out & out, const std::string & path, Value & root)
     }
 }
 
+bool has_example(Context & ctx, Value & option) {
+  try {
+      findAlongAttrPath(ctx.state, "example", ctx.autoArgs, option);
+      return true;
+  } catch (Error &) {
+      return false;
+  }
+}
+
 void printOption(Context & ctx, Out & out, const std::string & path, Value & option)
 {
     out << "Value:\n";
@@ -413,8 +422,10 @@ void printOption(Context & ctx, Out & out, const std::string & path, Value & opt
     out << "\n\nType:\n";
     printAttr(ctx, out, "type.description", option);
 
-    out << "\n\nExample:\n";
-    printAttr(ctx, out, "example", option);
+    if (has_example(ctx, option)) {
+        out << "\n\nExample:\n";
+        printAttr(ctx, out, "example", option);
+    }
 
     out << "\n\nDescription:\n";
     printAttr(ctx, out, "description", option);