Here’s a sample of youtube-dl --help
:
--postprocessor-args ARGS Give these arguments to the postprocessor
-k, --keep-video Keep the video file on disk after the
post-processing; the video is erased by
default
--no-post-overwrites Do not overwrite post-processed files;
the post-processed files are overwritten
by default
Now let’s the same options with Ruby’s OptionParser:
OptionParser.new do |opt|
opt.on(
'--postprocessor-args ARGS',
'Give these arguments to the postprocessor'
)
opt.on(
'-k', '--keep-video',
'Keep the video file on disk after the post-processing; the video is erased by default'
)
opt.on(
'--no-post-overwrites',
'Do not overwrite post-processed files; the post-processed files are overwritten by default'
)
end.parse!
The Result:
--postprocessor-args ARGS Give these arguments to the postprocessor
-k, --keep-video Keep the video file on disk after the pos
t-processing; the video is erased by default
--no-post-overwrites Do not overwrite post-processed files; th
e post-processed files are overwritten by default
It aligned short flags and long flags, which I guess is nice and better than Python’s argpase
(which youtube-dl
uses), but the help text didn’t take the width of my terminal window into consideration and continues from the start of the following line, which is harder to read.
I heaven’t found anything in documentation or tips online, but is there a way to achieve that same result? External gem
s can’t be used.
question from:
https://stackoverflow.com/questions/65947367/ruby-optionparser-with-help-in-column 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…