Class: Gemdiff::CLI
- Inherits:
-
Thor
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/gemdiff/cli.rb', line 47
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
|
#each ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/gemdiff/cli.rb', line 63
def each
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 %w[s A].include?(response)
outdated_gem.compare if %w[y A].include?(response)
puts outdated_gem.compare_url if response == "s"
break if response == "x"
end
end
|
#find(gem_name) ⇒ Object
17
18
19
20
21
22
23
24
25
|
# File 'lib/gemdiff/cli.rb', line 17
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
|
#list ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/gemdiff/cli.rb', line 80
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
38
39
40
|
# File 'lib/gemdiff/cli.rb', line 38
def main(gem_name)
find(gem_name).main
end
|
#open(gem_name) ⇒ Object
28
29
30
|
# File 'lib/gemdiff/cli.rb', line 28
def open(gem_name)
find(gem_name).open
end
|
#releases(gem_name) ⇒ Object
33
34
35
|
# File 'lib/gemdiff/cli.rb', line 33
def releases(gem_name)
find(gem_name).releases
end
|
#update(name) ⇒ Object
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/gemdiff/cli.rb', line 93
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
|