dnaeon / clingon

Command-line options parser system for Common Lisp
Other
122 stars 7 forks source link

About line breaks in the description #17

Closed simendsjo closed 11 months ago

simendsjo commented 11 months ago

First off, I absolutely love Clingon! Feature rich, easy to use, and everything just works! Had to write my own run to avoid the global error handler, but everything has been smooth sailing otherwise. The documentation is also great!

So this is a minor nitpick: Is it possible to have line-breaks in the source code without them being added in the help output? If the ~Newline directive was supported, I guess everything would work fine. If I have to keep everything on a single source lines, it becomes harder to maintain the documentation.

image image

EDIT: I would think adding a little format here would do the trick: https://github.com/dnaeon/clingon/blob/master/src/command.lisp#L1038 I.e. (wrap (format nil description))' instead of(wrap description)'

Of course, this means the descriptions have to be aware of using ~, which might be a bit intrusive..

dnaeon commented 11 months ago

Hey @simendsjo ,

Thanks for the kind words, happy to hear clingon serves you well :)

A solution for long-description would be to use (format nil description) ... before passing it to the :long-description initarg.

See here for example:

Another possible solution would be to provide your own CLINGON:COMMAND-LONG-DESCRIPTION method, which does (format nil ...), e.g.

(defmethod clingon:command-long-description ((command clingon:command))
  (with-slots (clingon.command::long-description) command
    (format nil clingon.command::long-description)))

Using this approach you can provide any FORMAT directive directly to the :long-description initarg.

Let me know what do you think.

Thanks!

simendsjo commented 11 months ago

Thanks! I actually just found the solution before looking back here ;) This is for the option description that was giving be problems:

(defmethod clingon:option-description :around ((option clingon:option))
  (format nil (call-next-method option)))

image image

EDIT: For reference, here's the three methods:

(defmethod clingon:command-description :around ((command clingon:command))
  (alex:when-let (value (call-next-method command))
    (format nil value)))

(defmethod clingon:command-long-description :around ((command clingon:command))
  (alex:when-let (value (call-next-method command))
    (format nil value)))

(defmethod clingon:option-description :around ((option clingon:option))
  (alex:when-let (value (call-next-method option))
    (format nil value)))
dnaeon commented 11 months ago

Nice! :)