Skip to content

Instantly share code, notes, and snippets.

@tkurtbond
Last active September 13, 2021 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkurtbond/6c23d93aacf0dfafa6333af64e5b34cc to your computer and use it in GitHub Desktop.
Save tkurtbond/6c23d93aacf0dfafa6333af64e5b34cc to your computer and use it in GitHub Desktop.
Modify args.scm from the CHICKEN Scheme args egg to not truncate long options and to allow multiple docstrings for multiple lines
;; O is an args:option
(define (usage-line o)
(define (pad-docstring docstring)
(string-append (string-pad "" (+ (args:width) (args:indent)))
docstring "\n"))
(let* ((option-string (commify o))
(docstrings (args:option-docstring o))
(first-docstring (if (string? docstrings) docstrings (car docstrings)))
(rest-docstrings (if (string? docstrings) '() (cdr docstrings)))
(s (string-append
(spaces (args:indent))
(cond
((>= (+ (args:indent) (string-length option-string))
(args:width))
;; Option is too wide, so split it over two lines.
(string-append option-string "\n"
(pad-docstring first-docstring)))
(else
(string-append
(string-pad-right option-string (args:width))
first-docstring "\n"))))))
(if (null? rest-docstrings)
;; Only one docstring, so just return it.
s
;; Mutiple docstrings, so format the rest and concatenate them to first.
(apply string-append (cons s (map pad-docstring rest-docstrings))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment