Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly pad aliases for option usage #810

Merged
merged 1 commit into from
May 10, 2023
Merged

Conversation

p8
Copy link
Member

@p8 p8 commented Feb 9, 2023

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 main option 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:

  -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)

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)

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]

Fixes: rails/rails#47258

@p8 p8 force-pushed the fix/option-padding branch 2 times, most recently from ea56567 to d2c5aa7 Compare February 9, 2023 16:13
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]
```
@byroot byroot merged commit ea10821 into rails:main May 10, 2023
@p8 p8 deleted the fix/option-padding branch May 10, 2023 11:12
@p8
Copy link
Member Author

p8 commented May 10, 2023

Thanks @byroot !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rails new command help weird groupings
2 participants