Commits

Moritz Heidkamp committed 6c8e688

chicken-build: add -h option to just show the help and terminate successfully (thanks Mario Goulart for the suggestion)

Comments (0)

Files changed (1)

chicken-build.scm

 (import (only setup-api remove-directory))
 (include "chicken-env")
 
-(define (print-error msg . args)
+(define (printf-error msg . args)
   (apply fprintf (current-error-port) msg args)
   (newline (current-error-port)))
 
-(define (usage)
-  (fail "Usage: ~A [OPTION ...] NAME
+(define (printf-newline msg . args)
+  (apply printf msg args)
+  (newline))
+
+(define (usage #!optional (print printf-newline))
+  (print "Usage: ~A [OPTION ...] NAME
 Build Chicken in current directory and install it to $CHICKENS/NAME.
 
 Options:
   -b  build and use a bootstrap Chicken
   -d  make a debug build
   -s  use NAME as PROGRAM_SUFFIX
-  -p  use NAME as PROGRAM_PREFIX"
-        (pathname-file (program-name))))
+  -p  use NAME as PROGRAM_PREFIX
+  -h  show this help"
+         (pathname-file (program-name))))
 
 (define build-boot-chicken? #f)
 (define debug-build? #f)
 (define chicken-name #f)
 
 (when (null? (command-line-arguments))
-  (usage))
+  (usage fail))
 
 (let loop ((args (command-line-arguments)))
   (match args
     (("-d" rest ...)
      (set! debug-build? #t)
      (loop rest))
+    (("-h" rest ...)
+     (usage)
+     (exit))
     ((name)
      (set! chicken-name name))
     (rest
-     (print-error "Invalid arguments: ~S" rest)
-     (usage))))
+     (printf-error "Invalid arguments: ~S" rest)
+     (usage fail))))
 
 (unless chicken-name
-  (usage))
+  (usage fail))
 
 (when (and suffix-name? prefix-name?)
   (fail "Only one of -p and -s can be passed"))