ruby / ruby/optparse

Would be nice if long descriptions were handled better

オープン
#104 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
Ruby
スター
71
フォーク
27
平均マージ
3時間 3分
マージ済み PR(30日)
2

説明

Consider:

require 'optparse'

options = {}

OptionParser.new do |opts|
  opts.banner = "Usage: #{$0} [options]"

  opts.on('-d', '--do-thing', 'Do a thing') do
    options[:do] = true
  end
  opts.on('-l', '--long-option', 'Here\'s an option with a pretty long description in order to see what OptionParser does with options with pretty long descriptions when the pretty long description is pretty long.') do
    options[:long] = l
  end
  opts.on('-s COUNT', '--do-some-more-things=COUNT', 'Do some more things') do |count|
    options[:more] = count
  end
end.parse!

p options
p ARGV

Then:

$ ruby opts.rb -h
Usage: opts.rb [options]
    -d, --do-thing                   Do a thing
    -l, --long-option                Here's an option with a pretty long description in order to see what OptionParser does with opt
ions with pretty long descriptions when the pretty long description is pretty long.
    -s, --do-some-more-things=COUNT  Do some more things

(I purposely wrapped it as I’d see it in a 132 column terminal window.)

It would be nice if OptionParser handled that better, getting the current terminal width and wrapping the description intelligently:

Usage: opts.rb [options]
    -d, --do-thing                   Do a thing
    -l, --long-option                Here's an option with a pretty long description in order to see what OptionParser does with
                                     options with pretty long descriptions when the pretty long description is pretty long.
    -s, --do-some-more-things=COUNT  Do some more things

I often write descriptions that would wrap in a 132 (or even more in an 80) column terminal window. When I manually write usages I handle that, but being OptionParser handles usage for me (very handy!) it would be nice if it did too.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

opts.rb に表示される OptionParser のヘルプ出力から始め、-h で使用されるフォーマット処理の経路を追跡します。表示されるインデントを維持しながら、端末の幅に基づいて長いオプション説明を折り返す処理を実装し、その後、例の出力がきれいに折り返されることを確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
ruby
領域
cli
issue の種類
機能追加
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。