Properly pad aliases for option usage#810
Merged
Merged
Conversation
ea56567 to
d2c5aa7
Compare
When printing the options of a command, options without aliases are padded so they aligned with options with aliases The size of the padding is calculated by multiplying the max number of aliases for an option by the number 4 (a dash, a letter, a comma and a space?). Options can have aliases of arbitrary length, not just just a dash with a single letter. For example in Rails the `main` option has the [alias](https://github.com/rails/rails/blob/main/railties/lib/rails/generators/app_base.rb#L100)` --master`. Also, the current implementation adds padding only to options without aliases. This results in strange output when callings `bin/rails new -h`: ```console -T, [--skip-test], [--no-skip-test] # Skip test files [--skip-system-test], [--no-skip-system-test] # Skip system test files [--skip-bootsnap], [--no-skip-bootsnap] # Skip bootsnap gem ... [--edge], [--no-edge] # Set up the application with a Gemfile pointing to the main branch on the Rails repository --master, [--main], [--no-main] # Set up the application with Gemfile pointing to Rails repository main branch ``` When printing the usage for options we should look at the actual formatted options. __Before (examples)__ ```console Usage: thor my_counter N [N] Options: -t, [--third=THREE] # The third argument # Default: 3 [--fourth=N] # The fourth argument z, [--simple=N] y, r, [--symbolic=N] ``` __After (examples)__ ```console Usage: thor my_counter N [N] Options: -t, [--third=THREE] # The third argument # Default: 3 [--fourth=N] # The fourth argument z, [--simple=N] y, r, [--symbolic=N] ```
d2c5aa7 to
17619ce
Compare
Member
Author
|
Thanks @byroot ! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When printing the options of a command, options without aliases are
padded so they align with options with aliases
The size of the padding is calculated by multiplying the max number of aliases
for an option by the number 4 (a dash, a letter, a comma and a space?).
Options can have aliases of arbitrary length, not just just a dash with
a single letter. For example in Rails the
mainoption has the alias--master.Also, the current implementation adds padding only to options without aliases.
So if one options has 1 alias and another has 2 aliases, the first option won't
get padding.
This all results in strange output when callings
bin/rails new -h:When printing the usage for options we should look at the actual
formatted options.
Before (examples)
After (examples)
Fixes: rails/rails#47258