ruby / ruby/optparse

Would be nice if long descriptions were handled better

Đang mở
#104 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
Ruby
Star
71
Fork
27
Merge trung bình
3 giờ 3 phút
Pull request đã merge (30 ngày)
2

Mô tả

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.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu từ phần đầu ra trợ giúp của OptionParser được hiển thị cho opts.rb và lần theo đường dẫn định dạng được -h sử dụng. Triển khai việc ngắt dòng cho các mô tả tùy chọn dài dựa trên chiều rộng của terminal, đồng thời giữ nguyên phần thụt lề được hiển thị, sau đó xác minh rằng đầu ra ví dụ được ngắt dòng rõ ràng.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
ruby
Lĩnh vực
cli
Loại issue
Tính năng
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
45/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.