Would be nice if long descriptions were handled better

Aperta
#104 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
ruby
Ambito
cli

Direzione di ricerca

Inizia dall’output dell’help di OptionParser mostrato per opts.rb e traccia il percorso di formattazione utilizzato da -h. Implementa il ritorno a capo per le descrizioni lunghe delle opzioni in base alla larghezza del terminale, mantenendo l’indentazione visualizzata, quindi verifica che l’output di esempio venga mandato a capo correttamente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Ruby
Stelle
71
Fork
27
Merge medio
3h 3m
PR unite (30g)
2

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ruby/optparse

Tutte le issue di ruby/optparse

Issue simili

Altre issue su Ruby

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.