Class: Gemdiff::CLI

Inherits:
Thor
  • Object
show all
Includes:
Colorize, Thor::Actions
Defined in:
lib/gemdiff/cli.rb

Constant Summary collapse

CHECKING_FOR_OUTDATED =
"Checking for outdated gems in your bundle..."
NOTHING_TO_UPDATE =
"Nothing to update."
WORKING_DIRECTORY_IS_NOT_CLEAN =
"Your working directory is not clean. Please commit or stash before updating."
RESPONSES_ALL =
%w[s A].freeze
RESPONSES_COMPARE =
%w[y A].freeze

Constants included from Colorize

Gemdiff::Colorize::COLORS

Instance Method Summary collapse

Methods included from Colorize

#colorize, #colorize_git_output

Instance Method Details

#compare(gem_name, old_version = nil, new_version = nil) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/gemdiff/cli.rb', line 49

def compare(gem_name, old_version = nil, new_version = nil)
  outdated_gem = find(gem_name)
  return unless outdated_gem.repo?
  outdated_gem.set_versions old_version, new_version
  if outdated_gem.missing_versions?
    puts CHECKING_FOR_OUTDATED
    unless outdated_gem.load_bundle_versions
      puts "#{gem_name} is not outdated in your bundle. Specify versions."
      return
    end
  end
  puts outdated_gem.compare_message
  outdated_gem.compare
end

#eachObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/gemdiff/cli.rb', line 65

def each
  puts CHECKING_FOR_OUTDATED
  inspector = BundleInspector.new
  puts inspector.outdated
  all_action = false
  inspector.list.each do |outdated_gem|
    puts outdated_gem.compare_message
    response = all_action || ask("Open? (y to open, x to exit, A to open all, s to show all to stdout, else skip)")
    all_action = response if RESPONSES_ALL.include?(response)
    outdated_gem.compare if RESPONSES_COMPARE.include?(response)
    puts outdated_gem.compare_url if response == "s"
    break if response == "x"
  end
end

#find(gem_name) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/gemdiff/cli.rb', line 19

def find(gem_name)
  outdated_gem = OutdatedGem.new(gem_name)
  if outdated_gem.repo?
    puts outdated_gem.repo
  else
    puts "Could not find github repository for #{gem_name}."
  end
  outdated_gem
end

#listObject



82
83
84
85
86
87
88
89
90
91
92
# File 'lib/gemdiff/cli.rb', line 82

def list
  puts CHECKING_FOR_OUTDATED
  inspector = BundleInspector.new
  puts inspector.outdated
  puts "\n"
  inspector.list.each do |outdated_gem|
    puts outdated_gem.compare_message
    puts outdated_gem.compare_url
    puts "\n"
  end
end

#main(gem_name) ⇒ Object



40
41
42
# File 'lib/gemdiff/cli.rb', line 40

def main(gem_name)
  find(gem_name).main
end

#open(gem_name) ⇒ Object



30
31
32
# File 'lib/gemdiff/cli.rb', line 30

def open(gem_name)
  find(gem_name).open
end

#releases(gem_name) ⇒ Object



35
36
37
# File 'lib/gemdiff/cli.rb', line 35

def releases(gem_name)
  find(gem_name).releases
end

#update(name) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/gemdiff/cli.rb', line 95

def update(name)
  gem_updater = GemUpdater.new(name)
  puts WORKING_DIRECTORY_IS_NOT_CLEAN unless gem_updater.clean?
  puts "Updating #{name}..."
  gem_updater.update
  diff_output = colorize_git_output(gem_updater.diff)
  puts diff_output
  if diff_output.empty?
    puts NOTHING_TO_UPDATE
    return
  end
  response = ask("\nCommit? (c to commit, r to reset, else do nothing)")
  case response
  when "c"
    gem_updater.commit
    puts "\n#{colorize_git_output(gem_updater.show)}"
  when "r"
    puts gem_updater.reset
  end
end