Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
443 views
in Technique[技术] by (71.8m points)

argparse - Ruby OptionParser with help in column?

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 gems can’t be used.

question from:https://stackoverflow.com/questions/65947367/ruby-optionparser-with-help-in-column

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...