Advertisement
Guest User

usage help string generator

a guest
May 13th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 0.94 KB | None | 0 0
  1. (define (usage specs lastrun)
  2.   (string-join
  3.    (map
  4.     (lambda (spec)
  5.       (let* ((long-name (car spec))
  6.          (props (cdr spec))
  7.          (single-char (assoc-ref props 'single-char))
  8.          (description (assoc-ref props 'description))
  9.          (value (assoc-ref props 'value))
  10.          (value-desc (assoc-ref props 'value-desc))
  11.          (default (assoc-ref props 'default))
  12.          (lastrun (hash-ref lastrun long-name)))
  13.     (string-append
  14.      (if single-char
  15.          (string #\- (car single-char)))
  16.      " "
  17.      (string-append "--" (symbol->string long-name))
  18.      (if value
  19.          (if value-desc
  20.          (string-append " " (car value-desc) "\n")
  21.          " ARG\n")
  22.          "\n")
  23.      (if description (car description) "NO DESCRIPTION")
  24.      (if value
  25.          (cond
  26.           (lastrun (string-append " (default " lastrun ")"))
  27.           (default (string-append " (default " (car default) ")"))
  28.           (else ""))
  29.          (if (or lastrun default) " (default)" "")))))
  30.     specs)
  31.    "\n\n"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement