Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distinguish between apps that auto-update and those marked as latest #53

Merged
merged 2 commits into from
Apr 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ Options:

```
Usage: brew cu [CASK] [options]
-a, --all Force upgrade outdated apps including those marked as latest and those that auto-update
-a, --all Include apps that auto-update in the upgrade
--cleanup Cleans up cached downloads and tracker symlinks after updating
-f --force Include apps that are marked as latest (i.e. force-reinstall them)
-y, --yes Update all outdated apps; answer yes to updating packages
```

Expand Down
7 changes: 5 additions & 2 deletions cmd/brew-cu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
#: Upgrade a specific app.
#:
#:OPTIONS:
#: If `--all` or `-a` is passed, force upgrade outdated apps including those
#: marked as latest and those that auto-update.
#: If `--all` or `-a` is passed, include apps that auto-update in the
#: upgrade.
#:
#: If `--cleanup` is passed, clean up cached downloads and tracker symlinks
#: after updating.
#:
#: If `--force` or `-f` is passed, include apps that are marked as latest
#: (i.e. force-reinstall them).
#:
#: If `--yes` or `-y` is passed, update all outdated apps; answer yes to
#: updating packages.

Expand Down
63 changes: 28 additions & 35 deletions lib/bcu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ module Bcu
def self.process(args)
parse!(args)

outdated = find_outdated_apps
outdated, state_info = find_outdated_apps
return if outdated.empty?

print_outdated_app(outdated)
puts
ohai "Found outdated apps"
print_app_table(outdated, state_info)

if options.dry_run
printf "\nDo you want to upgrade %d app%s [y/N]? ", outdated.length, outdated.length > 1 ? "s" : ""
Expand Down Expand Up @@ -47,6 +49,7 @@ def self.process(args)

def self.find_outdated_apps
outdated = []
state_info = Hash.new("")

ohai "Finding outdated apps"
installed = Hbc.installed_apps
Expand All @@ -59,58 +62,48 @@ def self.find_outdated_apps
end
end

table = [["No.", "Name", "Cask", "Current", "Latest", "Auto-Update", "State"]]
installed.each_with_index do |app, i|
row = []
row << "#{i+1}/#{installed.length}"
row << app[:name].to_s
row << app[:token]
row << app[:current].join(", ")
row << app[:version]
row << (app[:auto_updates] ? "Y" : "")
if options.all && app[:version] == "latest"
row << "forced to upgrade"
installed.each do |app|
version_latest = (app[:version] == "latest")

if options.force && options.all && version_latest && app[:auto_updates]
outdated.push app
state_info[app] = "forced to reinstall"
elsif options.force && version_latest && !app[:auto_updates]
outdated.push app
elsif options.all && app[:auto_updates] && app[:outdated?]
row << "forced to upgrade"
state_info[app] = "forced to reinstall"
elsif options.all && !version_latest && app[:auto_updates] && app[:outdated?]
outdated.push app
elsif !options.all && app[:auto_updates]
row << "ignored"
elsif app[:outdated?]
row << "outdated"
state_info[app] = "forced to upgrade"
elsif !version_latest && !app[:auto_updates] && app[:outdated?]
outdated.push app
state_info[app] = "outdated"
elsif version_latest || app[:outdated?]
state_info[app] = "ignored"
elsif app[:cask].nil?
row << "no cask available"
state_info[app] = "no cask available"
end
table << row
end
puts Formatter.table(table)

outdated
print_app_table(installed, state_info)

[outdated, state_info]
end

def self.print_outdated_app(outdated)
def self.print_app_table(apps, state_info)
table = [["No.", "Name", "Cask", "Current", "Latest", "Auto-Update", "State"]]
outdated.each_with_index do |app, i|

apps.each_with_index do |app, i|
row = []
row << "#{i+1}/#{outdated.length}"
row << "#{i+1}/#{apps.length}"
row << app[:name].to_s
row << app[:token]
row << app[:current].join(", ")
row << app[:version]
row << (app[:auto_updates] ? "Y" : "")
if options.all && app[:version] == "latest"
row << "forced to upgrade"
elsif options.all && app[:auto_updates] && app[:outdated?]
row << "forced to upgrade"
elsif app[:outdated?]
row << "outdated"
end
row << state_info[app]
table << row
end

puts
ohai "Found outdated apps"
puts Formatter.table(table)
end
end
7 changes: 6 additions & 1 deletion lib/bcu/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,26 @@ class << self; attr_accessor :options; end
def self.parse!(args)
options = OpenStruct.new
options.all = false
options.force = false
options.cask = nil
options.cleanup = false
options.dry_run = true

parser = OptionParser.new do |opts|
opts.banner = "Usage: brew cu [CASK] [options]"

opts.on("-a", "--all", "Force upgrade outdated apps including those marked as latest and those that auto-update") do
opts.on("-a", "--all", "Include apps that auto-update in the upgrade") do
options.all = true
end

opts.on("--cleanup", "Cleans up cached downloads and tracker symlinks after updating") do
options.cleanup = true
end

opts.on("-f", "--force", "Include apps that are marked as latest (i.e. force-reinstall them)") do
options.force = true
end

opts.on("-y", "--yes", "Update all outdated apps; answer yes to updating packages") do
options.dry_run = false
end
Expand Down