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."

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



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/gemdiff/cli.rb', line 45

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

#find(gem_name) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/gemdiff/cli.rb', line 15

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



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/gemdiff/cli.rb', line 77

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

#master(gem_name) ⇒ Object



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

def master(gem_name)
  find(gem_name).master
end

#open(gem_name) ⇒ Object



26
27
28
# File 'lib/gemdiff/cli.rb', line 26

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

#outdatedObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/gemdiff/cli.rb', line 61

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

#releases(gem_name) ⇒ Object



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

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

#update(name) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/gemdiff/cli.rb', line 90

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)")
  if response == "c"
    gem_updater.commit
    puts "\n" + colorize_git_output(gem_updater.show)
  elsif response == "r"
    puts gem_updater.reset
  end
end