Class: NextRails::BundleReport::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/next_rails/bundle_report/cli.rb

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CLI

Returns a new instance of CLI.



9
10
11
12
# File 'lib/next_rails/bundle_report/cli.rb', line 9

def initialize(argv)
  validate_arguments(argv)
  @argv = argv
end

Instance Method Details

#runObject



35
36
37
38
# File 'lib/next_rails/bundle_report/cli.rb', line 35

def run
  options = parse_options
  execute_report(@argv.first, options)
end

#validate_arguments(argv) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/next_rails/bundle_report/cli.rb', line 14

def validate_arguments(argv)
  return unless argv.any?

  valid_report_types = %w[outdated compatibility ruby_check]
  report_type = argv.first

  unless valid_report_types.include?(report_type)
    raise ArgumentError, "Invalid report type '#{report_type}'. Valid types are: #{valid_report_types.join(', ')}."
  end

  argv.each do |arg|
    if arg.start_with?("--rails-version") && !/--rails-version=+\d+(\.\d+)*$/.match(arg)
      raise ArgumentError, "Invalid Rails version format. Example: --rails-version=5.0.7"
    end

    if arg.start_with?("--ruby-version") && !/--ruby-version=+\d+(\.\d+)*$/.match(arg)
      raise ArgumentError, "Invalid Ruby version format. Example: --ruby-version=3.3"
    end
  end
end