Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
440 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 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...