Skip to content

Commit

Permalink
Distinguish between "auto-update" and "latest" apps
Browse files Browse the repository at this point in the history
As a follow-up to 40baf90, this adds a separation between apps that
auto-update and those that are marked as latest through new command line
options: `--all` now includes apps that auto-update, while `--force` is
(additionally or exclusively) required for apps marked as latest.

The rationale behind this is to allow upgrades of apps that auto-update
without always reinstalling such marked as latest.
  • Loading branch information
F30 committed Mar 26, 2017
1 parent 20675db commit 15ccfa6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
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
17 changes: 11 additions & 6 deletions lib/bcu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,22 @@ def self.find_outdated_apps
end

installed.each do |app|
if options.all && app[:version] == "latest"
version_latest = (app[:version] == "latest")

if options.force && options.all && version_latest && app[:auto_updates]
outdated.push app
state_info[app] = "forced to upgrade"
elsif options.all && app[:auto_updates] && app[:outdated?]
state_info[app] = "forced to reinstall"
elsif options.force && version_latest && !app[:auto_updates]
outdated.push app
state_info[app] = "forced to reinstall"
elsif options.all && !version_latest && app[:auto_updates] && app[:outdated?]
outdated.push app
state_info[app] = "forced to upgrade"
elsif !options.all && app[:auto_updates]
state_info[app] = "ignored"
elsif app[:outdated?]
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?
state_info[app] = "no cask available"
end
Expand Down
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

0 comments on commit 15ccfa6

Please sign in to comment.