Class: Appraisal::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/appraisal/cli.rb

Constant Summary collapse

MINIMUM_PARALLEL_BUNDLER_VERSION =
Gem::Version.new("2.1.0")

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object (private)



242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
# File 'lib/appraisal/cli.rb', line 242

def method_missing(name, *args)
  case name.to_s
  when "generate-install"
    return generate_install
  when "generate-update"
    return generate_update(*args)
  end

  matching_appraisal = AppraisalFile.new.appraisals.detect do |appraisal|
    appraisal.name == name.to_s
  end

  if matching_appraisal
    # If no arguments were passed to method_missing, check ARGV
    # This handles cases where Thor doesn't pass arguments
    actual_args = (args.empty? && ARGV.any?) ? ARGV.dup : args

    # Check if the first argument is an appraisal subcommand.
    if actual_args.first == "generate"
      matching_appraisal.write_gemfile
    elsif actual_args.first == "install"
      # Extract Thor options from the remaining arguments
      # Filter out the command name and pass options to install
      filtered_args = actual_args[1..-1] || []
      # Parse the options ourselves since Thor isn't parsing them here
      parsed_options = parse_external_options(filtered_args)

      # Also include the class-level gem_manager option if provided
      # Thor consumes class_option before calling method_missing, so check both places
      gem_manager = options["gem-manager"] || options[:gem_manager]
      parsed_options[:gem_manager] = gem_manager if gem_manager && !parsed_options.key?(:gem_manager)

      matching_appraisal.install(parsed_options)
      matching_appraisal.relativize
    elsif actual_args.first == "generate-install"
      filtered_args = actual_args[1..-1] || []
      parsed_options = parse_external_options(filtered_args)

      gem_manager = options["gem-manager"] || options[:gem_manager]
      parsed_options[:gem_manager] = gem_manager if gem_manager && !parsed_options.key?(:gem_manager)

      matching_appraisal.write_gemfile
      matching_appraisal.install(parsed_options)
      matching_appraisal.relativize
    elsif actual_args.first == "update"
      # Extract gems and options
      filtered_args = actual_args[1..-1] || []
      gems, parsed_options = extract_gems_and_options(filtered_args)

      # Also include the class-level gem_manager option if provided
      gem_manager = options["gem-manager"] || options[:gem_manager]
      parsed_options[:gem_manager] = gem_manager if gem_manager && !parsed_options.key?(:gem_manager)

      matching_appraisal.update(gems, parsed_options)
    elsif actual_args.first == "generate-update"
      filtered_args = actual_args[1..-1] || []
      gems, parsed_options = extract_gems_and_options(filtered_args)

      gem_manager = options["gem-manager"] || options[:gem_manager]
      parsed_options[:gem_manager] = gem_manager if gem_manager && !parsed_options.key?(:gem_manager)

      matching_appraisal.write_gemfile
      matching_appraisal.update(gems, parsed_options)
    else
      # Run as an external command
      Command.new(actual_args, :gemfile => matching_appraisal.gemfile_path).run
    end
  else
    each_appraisal(AppraisalFile.new.appraisals, appraisal_jobs(options)) do |appraisal|
      Command.new(ARGV, :gemfile => appraisal.gemfile_path).run
    end
  end
end

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/appraisal/cli.rb', line 54

def exit_on_failure?
  true
end

.help(shell, subcommand = false) ⇒ Object

Override help command to print out usage



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/appraisal/cli.rb', line 29

def help(shell, subcommand = false)
  shell.say(strip_heredoc(<<-HELP))
    Appraisal: Find out what your Ruby gems are worth.

    Usage:
      appraisal [APPRAISAL_NAME] EXTERNAL_COMMAND

      If APPRAISAL_NAME is given, only run that EXTERNAL_COMMAND against the given
      appraisal, otherwise it runs the EXTERNAL_COMMAND against all appraisals.
  HELP

  if File.exist?("Appraisals")
    shell.say
    shell.say("Available Appraisal(s):")

    AppraisalFile.each do |appraisal|
      shell.say("  - #{appraisal.name}")
    end
  end

  shell.say

  super
end

Instance Method Details

#cleanObject



129
130
131
# File 'lib/appraisal/cli.rb', line 129

def clean
  FileUtils.rm_f(Dir["gemfiles/*.{gemfile,gemfile.lock}"])
end

#generateObject



124
125
126
# File 'lib/appraisal/cli.rb', line 124

def generate
  generate_appraisals(appraisals, appraisal_jobs(options))
end

#generate_installObject



117
118
119
120
121
# File 'lib/appraisal/cli.rb', line 117

def generate_install
  appraisal_list = appraisals
  generate_appraisals(appraisal_list, appraisal_jobs(options))
  install_appraisals(appraisal_list, install_options, appraisal_jobs(options))
end

#generate_update(*gems) ⇒ Object



139
140
141
142
143
# File 'lib/appraisal/cli.rb', line 139

def generate_update(*gems)
  appraisal_list = appraisals
  generate_appraisals(appraisal_list, appraisal_jobs(options))
  update_appraisals(appraisal_list, gems, update_options, appraisal_jobs(options))
end

#installObject



90
91
92
# File 'lib/appraisal/cli.rb', line 90

def install
  install_appraisals(appraisals, install_options, appraisal_jobs(options))
end

#listObject



146
147
148
# File 'lib/appraisal/cli.rb', line 146

def list
  AppraisalFile.new.appraisals.each { |appraisal| puts appraisal.name }
end

#update(*gems) ⇒ Object



134
135
136
# File 'lib/appraisal/cli.rb', line 134

def update(*gems)
  update_appraisals(appraisals, gems, update_options, appraisal_jobs(options))
end

#versionObject



151
152
153
# File 'lib/appraisal/cli.rb', line 151

def version
  puts "Appraisal2 #{VERSION}"
end