@@ -9,10 +9,12 @@ module Bcu
9
9
def self . process ( args )
10
10
parse! ( args )
11
11
12
- outdated = find_outdated_apps
12
+ outdated , state_info = find_outdated_apps
13
13
return if outdated . empty?
14
14
15
- print_outdated_app ( outdated )
15
+ puts
16
+ ohai "Found outdated apps"
17
+ print_app_table ( outdated , state_info )
16
18
17
19
if options . dry_run
18
20
printf "\n Do you want to upgrade %d app%s [y/N]? " , outdated . length , outdated . length > 1 ? "s" : ""
@@ -47,6 +49,7 @@ def self.process(args)
47
49
48
50
def self . find_outdated_apps
49
51
outdated = [ ]
52
+ state_info = Hash . new ( "" )
50
53
51
54
ohai "Finding outdated apps"
52
55
installed = Hbc . installed_apps
@@ -59,58 +62,43 @@ def self.find_outdated_apps
59
62
end
60
63
end
61
64
62
- table = [ [ "No." , "Name" , "Cask" , "Current" , "Latest" , "Auto-Update" , "State" ] ]
63
- installed . each_with_index do |app , i |
64
- row = [ ]
65
- row << "#{ i +1 } /#{ installed . length } "
66
- row << app [ :name ] . to_s
67
- row << app [ :token ]
68
- row << app [ :current ] . join ( ", " )
69
- row << app [ :version ]
70
- row << ( app [ :auto_updates ] ? "Y" : "" )
65
+ installed . each do |app |
71
66
if options . all && app [ :version ] == "latest"
72
- row << "forced to upgrade"
73
67
outdated . push app
68
+ state_info [ app ] = "forced to upgrade"
74
69
elsif options . all && app [ :auto_updates ] && app [ :outdated? ]
75
- row << "forced to upgrade"
76
70
outdated . push app
71
+ state_info [ app ] = "forced to upgrade"
77
72
elsif !options . all && app [ :auto_updates ]
78
- row << "ignored"
73
+ state_info [ app ] = "ignored"
79
74
elsif app [ :outdated? ]
80
- row << "outdated"
81
75
outdated . push app
76
+ state_info [ app ] = "outdated"
82
77
elsif app [ :cask ] . nil?
83
- row << "no cask available"
78
+ state_info [ app ] = "no cask available"
84
79
end
85
- table << row
86
80
end
87
- puts Formatter . table ( table )
88
81
89
- outdated
82
+ print_app_table ( installed , state_info )
83
+
84
+ [ outdated , state_info ]
90
85
end
91
86
92
- def self . print_outdated_app ( outdated )
87
+ def self . print_app_table ( apps , state_info )
93
88
table = [ [ "No." , "Name" , "Cask" , "Current" , "Latest" , "Auto-Update" , "State" ] ]
94
- outdated . each_with_index do |app , i |
89
+
90
+ apps . each_with_index do |app , i |
95
91
row = [ ]
96
- row << "#{ i +1 } /#{ outdated . length } "
92
+ row << "#{ i +1 } /#{ apps . length } "
97
93
row << app [ :name ] . to_s
98
94
row << app [ :token ]
99
95
row << app [ :current ] . join ( ", " )
100
96
row << app [ :version ]
101
97
row << ( app [ :auto_updates ] ? "Y" : "" )
102
- if options . all && app [ :version ] == "latest"
103
- row << "forced to upgrade"
104
- elsif options . all && app [ :auto_updates ] && app [ :outdated? ]
105
- row << "forced to upgrade"
106
- elsif app [ :outdated? ]
107
- row << "outdated"
108
- end
98
+ row << state_info [ app ]
109
99
table << row
110
100
end
111
101
112
- puts
113
- ohai "Found outdated apps"
114
102
puts Formatter . table ( table )
115
103
end
116
104
end
0 commit comments