]> Repositorios git - classgraph.git/commitdiff
Add --haddock to classgraph-plugin-flag.sh
authorJavier Sagredo <[email protected]>
Thu, 18 Jun 2026 22:49:51 +0000 (00:49 +0200)
committerJavier Sagredo <[email protected]>
Thu, 18 Jun 2026 22:49:51 +0000 (00:49 +0200)
Optionally emit a -haddock ghc-option alongside the plugin flag. The plugin
only harvests Haddock comments (the side-panel docs) when the target is
compiled with -haddock, so this saves adding it by hand. Works in both the
raw and --cabal forms; off by default.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
classgraph-plugin-flag.sh

index 68f182f00c1d4e8ee50af0a5c7b7be4ec771f03a..a425045ae90b826ab68c3935ad8dbb4d3b4b57ea 100755 (executable)
@@ -56,6 +56,10 @@ Options:
                   --package it is a 'package PKG' block.
   --package PKG   Scope the --cabal stanza to the single package PKG. Only
                   meaningful together with --cabal.
+  --haddock       Also emit a -haddock ghc-option. The plugin only captures
+                  Haddock comments (class/instance/family docs in the side
+                  panel) when the target is compiled with -haddock, so add
+                  this if you want documentation in the graph.
   -h, --help      Show this help and exit.
 
 Environment:
@@ -81,11 +85,13 @@ EOF
 DIR=.classgraph
 EMIT=raw      # raw | cabal
 PACKAGE=
+HADDOCK=      # non-empty → also emit -haddock
 while [ $# -gt 0 ]; do
   case "$1" in
     --dir)     DIR=$2; shift 2 ;;
     --cabal)   EMIT=cabal; shift ;;
     --package) PACKAGE=$2; shift 2 ;;
+    --haddock) HADDOCK=1; shift ;;
     -h|--help) usage; exit 0 ;;
     *)
       echo "$PROG: unknown argument: $1" >&2
@@ -236,13 +242,19 @@ CABAL_FLAG=$(printf '%s;%s;Classgraph.Plugin;"[\\"dir=%s\\"]"' \
 
 case "$EMIT" in
   raw)
+    # Each ghc-option on its own line so the output can be pasted/sourced
+    # token by token.
+    [ -n "$HADDOCK" ] && echo "-haddock"
     echo "$RAW_FLAG"
     ;;
   cabal)
     if [ -n "$PACKAGE" ]; then
-      printf 'package %s\n  ghc-options:\n    %s\n' "$PACKAGE" "$CABAL_FLAG"
+      echo "package $PACKAGE"
     else
-      printf 'program-options\n  ghc-options:\n    %s\n' "$CABAL_FLAG"
+      echo "program-options"
     fi
+    echo "  ghc-options:"
+    [ -n "$HADDOCK" ] && echo "    -haddock"
+    echo "    $CABAL_FLAG"
     ;;
 esac