1
1
# frozen_string_literal: true
2
2
3
- require 'optparse'
4
- require 'next_rails'
5
- require 'next_rails/bundle_report'
3
+ require "optparse"
4
+ require "next_rails"
5
+ require "next_rails/bundle_report"
6
+
6
7
class NextRails ::BundleReport ::CLI
7
8
def initialize ( argv )
9
+ validate_arguments ( argv )
8
10
@argv = argv
9
- validate_arguments ( @argv )
10
11
end
11
12
12
13
def validate_arguments ( argv )
@@ -20,12 +21,12 @@ def validate_arguments(argv)
20
21
end
21
22
22
23
argv . each do |arg |
23
- if arg . start_with? ( ' --rails-version' ) && !arg . match? ( /--rails-version=+\d +(\. \d +)*$/ )
24
- raise ArgumentError , ' Invalid Rails version format. Example: --rails-version=5.0.7'
24
+ if arg . start_with? ( " --rails-version" ) && !arg . match? ( /--rails-version=+\d +(\. \d +)*$/ )
25
+ raise ArgumentError , " Invalid Rails version format. Example: --rails-version=5.0.7"
25
26
end
26
27
27
- if arg . start_with? ( ' --ruby-version' ) && !arg . match? ( /--ruby-version=+\d +(\. \d +)*$/ )
28
- raise ArgumentError , ' Invalid Ruby version format. Example: --ruby-version=3.3'
28
+ if arg . start_with? ( " --ruby-version" ) && !arg . match? ( /--ruby-version=+\d +(\. \d +)*$/ )
29
+ raise ArgumentError , " Invalid Ruby version format. Example: --ruby-version=3.3"
29
30
end
30
31
end
31
32
end
@@ -58,28 +59,28 @@ def parse_options
58
59
59
60
EOS
60
61
61
- opts . separator ''
62
- opts . separator ' Options:'
62
+ opts . separator ""
63
+ opts . separator " Options:"
63
64
64
- opts . on ( ' --rails-version [STRING]' ,
65
- ' Rails version to check compatibility against (defaults to 5.0)' ) do |rails_version |
65
+ opts . on ( " --rails-version [STRING]" ,
66
+ " Rails version to check compatibility against (defaults to 5.0)" ) do |rails_version |
66
67
options [ :rails_version ] = rails_version
67
68
end
68
69
69
- opts . on ( ' --ruby-version [STRING]' ,
70
- ' Ruby version to check compatibility against (defaults to 2.3)' ) do |ruby_version |
70
+ opts . on ( " --ruby-version [STRING]" ,
71
+ " Ruby version to check compatibility against (defaults to 2.3)" ) do |ruby_version |
71
72
options [ :ruby_version ] = ruby_version
72
73
end
73
74
74
- opts . on ( ' --include-rails-gems' , ' Include Rails gems in compatibility report (defaults to false)' ) do
75
+ opts . on ( " --include-rails-gems" , " Include Rails gems in compatibility report (defaults to false)" ) do
75
76
options [ :include_rails_gems ] = true
76
77
end
77
78
78
- opts . on ( ' --json' , ' Output JSON in outdated report (defaults to false)' ) do
79
- options [ :format ] = ' json'
79
+ opts . on ( " --json" , " Output JSON in outdated report (defaults to false)" ) do
80
+ options [ :format ] = " json"
80
81
end
81
82
82
- opts . on_tail ( '-h' , ' --help' , ' Show this message' ) do
83
+ opts . on_tail ( "-h" , " --help" , " Show this message" ) do
83
84
puts opts
84
85
exit
85
86
end
@@ -98,16 +99,16 @@ def parse_options
98
99
99
100
def execute_report ( report_type , options )
100
101
case report_type
101
- when ' ruby_check'
102
+ when " ruby_check"
102
103
NextRails ::BundleReport . compatible_ruby_version ( rails_version : options . fetch ( :rails_version ) )
103
- when ' outdated'
104
+ when " outdated"
104
105
NextRails ::BundleReport . outdated ( options . fetch ( :format , nil ) )
105
106
else
106
107
if options [ :ruby_version ]
107
- NextRails ::BundleReport . ruby_compatibility ( ruby_version : options . fetch ( :ruby_version , ' 2.3' ) )
108
+ NextRails ::BundleReport . ruby_compatibility ( ruby_version : options . fetch ( :ruby_version , " 2.3" ) )
108
109
else
109
110
NextRails ::BundleReport . rails_compatibility (
110
- rails_version : options . fetch ( :rails_version , ' 5.0' ) ,
111
+ rails_version : options . fetch ( :rails_version , " 5.0" ) ,
111
112
include_rails_gems : options . fetch ( :include_rails_gems , false )
112
113
)
113
114
end
0 commit comments