c-blake / cligen

Nim library to infer/generate command-line-interfaces / option / argument parsing; Docs at
https://c-blake.github.io/cligen/
ISC License
496 stars 23 forks source link

Custom render function doesn't seem to receive the help text #182

Closed halloleo closed 3 years ago

halloleo commented 3 years ago

Again an issue from me! So I guess the first thing I really should mention is that I very much like cligen. It's a great piece of library!

Anyway, I tried a custom render proc for the help output in a dispatchMulti CLI, but even in a simple form:

proc render (s: string): string =
  return &">>>{s}<<<"

...
clCfg.render = render
...

the result is rather a surprise to me: It seems to only affect the doc string! Do I do something wrong?


ps: I went down the custom render path, because I am trying to eliminate the argument type column from the help output, but I guess, a custom render is not the way to go...

pps: I am using the HEAD version of cligen.

c-blake commented 3 years ago

render is really a "mid processor" (not post or pre..closer to pre). It is more for things like ANSI SGR highlighting. There the rendered size in text columns can be much smaller than the number of bytes which can really impact wrapping (with render(s).printedLen much less than s.len you can wrap much later). So, word wrapping happens after.

It applies both to help columns for params and to (inferred or passed) doc comment text. It may not impact help if you did not pass any since cligen cannot infer help.

It looks like what you really want is test/HelpTabCols.nim, though. So, I am closing this issue. There really are a lot of features, only weakly documented outside the code itself or issues that people have raised. So, you should probably get used to (as the README says) look at test/ or search the github issues.

halloleo commented 3 years ago

Thanks for the tip with test/HelpTabCols.nim! Will have a look. And you are right I should read the tests in detail...

halloleo commented 3 years ago

That's exactly what I needed: clCfg.hTabCols = @[ clOptKeys, clDflVal, clDescrip] Thanks again!

c-blake commented 3 years ago

Sure thing.

I tried to name the test/demo programs descriptively, but that competes with "short names". Also, because it takes almost 5 seconds to run all 60 of them (with cc=tcc in my nim.cfg) I have occasionally "cheated" and used one program for >1 purpose. :-)

Someone (you, maybe?) should write up 60..90 line "index" on the wiki of "how to do X: see test/Y". Of course people who don't read test/ may also not read the wiki (or search back GH issues) but that wiki page may make it more "automatically searchable".