Loading

--help problem

  1. (use-modules (config)
  2.              (config api)
  3.              (ice-9 format)
  4.              (ice-9 match))
  5.  
  6.  
  7. ;;; CONSTANTS
  8. ;;; =========
  9.  
  10. (define FRUITS
  11.   (list "apple" "banana" "kiwi" "mango"))
  12.  
  13.  
  14.  
  15. ;;; VALIDATORS
  16. ;;; ==========
  17.  
  18. (define (fruit? fruit)
  19.   (member fruit FRUITS))
  20.  
  21.  
  22.  
  23. ;;; ARGUMENTS AND OPTIONS
  24. ;;; =====================
  25.  
  26. (define fruit
  27.   (argument (name 'fruit)
  28.             (synopsis "The name of a fruit.")
  29.             (example "apple")
  30.             (optional? #false)
  31.             (test fruit?)))
  32.  
  33.  
  34.  
  35. ;;; CLI SPECIFICATION
  36. ;;; =================
  37.  
  38. (define spec
  39.   (configuration
  40.    (name 'eat)
  41.    (synopsis "Eat imaginary fruits.")
  42.    (version "1.0")
  43.    (arguments (list fruit))))
  44.  
  45.  
  46.  
  47. ;;; CLI DISPATCHER
  48. ;;; ==============
  49.  
  50. (define (dispatcher command spec)
  51.   #| Execute the appropriate procedure for the given COMMAND if it is
  52.   part of the given command-line interface specification.
  53.  
  54.   COMMAND (list of strings)
  55.     A list of strings that represent a command-line instruction passed
  56.     to the program (see the Guile command-line procedure).
  57.  
  58.   SPEC (Configuration)
  59.     A <configuration> record as specified by the guile-config library
  60.     specifying the command-line interface of the program.
  61.  
  62.   RESULT
  63.     Execute the COMMAND or display help information if the COMMAND is
  64.     not recognized. |#
  65.   (let* ((options (getopt-config-auto command spec))
  66.          (fruit (option-ref options '(fruit))))
  67.     (catch 'match-error
  68.       (lambda ()
  69.         (match (full-command options)
  70.           ((_) (format #true "What yummy ~a!!~%" fruit))))
  71.  
  72.       (lambda (. args)
  73.         (begin (display "ERROR: Command not found.")
  74.                (newline) (newline)
  75.                (emit-help options))))))
  76.  
  77.  
  78.  
  79. ;;; RUN
  80. ;;; ===
  81.  
  82. (dispatcher (command-line) spec)