Skip to content

Commit

Permalink
Rails 7.1 changed CLI output slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
mernen committed Nov 3, 2023
1 parent 6914289 commit c5e0340
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
33 changes: 30 additions & 3 deletions completion-rails
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,37 @@ __rails() {
else
case $rails_command in
"")
# Output until v7.0 when outside of a Rails project:
# > Usage:
# > rails new APP_PATH [options]
# (...)
# > Runtime options:
# -f, [--force] # (...)
#
# Output beginning with v7.1:
# > Usage:
# > rails COMMAND [options]
# >
# > You must specify a command:
# >
# > new Create a new (...)
#
# Output beginning with v7.1 when in a Rails project:
# > Usage:
# > bin/rails COMMAND [options]
# >
# > You must specify a command. The most common commands are:
# >
# > generate Generate new code (short-cut alias: "g")
# (...)
# > In addition to those commands, there are:
# >
# > about List versions (...)
options=$(__rails_exec --help \|\
'puts $1 if ~/^ rails (\S+)/;
puts $1 if ~/^ (\S+)/;
puts $1 if ~/alias: "(\S+)"/')
'puts $1 if ~/^ rails (?!COMMAND\b)(\S+)/;
puts $1 if ~/^ {1,2}(\S+)/;
puts $1 if ~/alias: "(\S+)"/;
puts $1 if ~/^(\w+(:\w+)*)((?<=\[)\S+\])? {2,}\w/')
# If you've already typed one character, let's skip the
# single-character shortcuts; this way, typing in "rails c<TAB>"
# will instantly complete to "console", rather than just beeping
Expand Down
2 changes: 1 addition & 1 deletion tests/completion-rails/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ begin-test 'when outside of a Rails project, should offer the command `new`'
(
test-completion rails ''
expect new
reject generate console
reject generate
)
end-test

Expand Down

0 comments on commit c5e0340

Please sign in to comment.