bcupgrade 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b04441667afbe6aa701b887cf5a55de828f99c9
4
- data.tar.gz: 9a99269c171fe4524d980e084bf0be369d5c635e
3
+ metadata.gz: 0f6ea276e941fdf9a1c046ad95626ac191844e53
4
+ data.tar.gz: 7349da2bbac7d1e40dc3decafa74b3cd1bdf40f4
5
5
  SHA512:
6
- metadata.gz: 1e651651d91a900334ff9cc4df52a7f389c0a81b0b95a11e65416d627ee25d504eea10c402a06ac260fc89cef815c084770b0ec6f44ee4ec8fb73953405bdb7b
7
- data.tar.gz: f4a66c1959469b6495e1e114a22de0e9bc184a4fb7830ad9051dab88327814895d44cbe09df0e45e1b7d0ef84fa3a3c0546e0865946e9bfa609b3c7a64a18dfe
6
+ metadata.gz: ed4987fcaf4b95556df4e7f76c4fe2d27869191270fcea4a758c018445ff1f124530d3376e3b4950c21ad1a17ae6c60730fab1241181f2839d2e69b30e124100
7
+ data.tar.gz: 59291b4a0da5330bc6022fa72f0b17fc2fb28e72e02ccff7f6b3d0481ba95bb950d2a14376facd138c0f31ea24a3bcc8684a0852885bc40115a4f09266935b01
data/.rubocop.yml CHANGED
@@ -6,3 +6,11 @@ AllCops:
6
6
 
7
7
  LineLength:
8
8
  Max: 120
9
+
10
+ Metrics/BlockLength:
11
+ Exclude:
12
+ - 'spec/**/*'
13
+ - 'test/**/*'
14
+
15
+ RSpec/NestedGroups:
16
+ Max: 4
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2017-03-24 21:37:30 +0900 using RuboCop version 0.47.1.
3
+ # on 2017-03-29 17:12:14 +0900 using RuboCop version 0.47.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -8,22 +8,18 @@
8
8
 
9
9
  # Offense count: 1
10
10
  Metrics/AbcSize:
11
- Max: 19
12
-
13
- # Offense count: 2
14
- # Configuration parameters: CountComments, ExcludedMethods.
15
- Metrics/BlockLength:
16
- Max: 92
11
+ Max: 16
17
12
 
18
13
  # Offense count: 2
19
14
  # Configuration parameters: CountComments.
20
15
  Metrics/MethodLength:
21
- Max: 23
16
+ Max: 17
22
17
 
23
- # Offense count: 2
18
+ # Offense count: 3
24
19
  Style/Documentation:
25
20
  Exclude:
26
21
  - 'spec/**/*'
27
22
  - 'test/**/*'
28
23
  - 'lib/bcupgrade.rb'
29
24
  - 'lib/bcupgrade/brew_cask.rb'
25
+ - 'lib/bcupgrade/cask.rb'
data/README.md CHANGED
@@ -34,13 +34,18 @@ Atom.app (app)
34
34
  ## Usage
35
35
 
36
36
  ```
37
- % bcupgrade -h
37
+ % bcupgrade --help
38
38
  Usage: bcupgrade [options]
39
+ -d, --dry-run Show output without running
40
+ -r, --remove Remove previous version casks with installing
41
+ -y, --yes Install cask without prompt
39
42
  -v, --version Show version number
40
- --dry-run Show output without running
41
43
  ```
42
44
 
43
- `bcupgrade` displays a confirmation prompt `[y/n]` when it attempts to re-install.
45
+ `bcupgrade` with no arguments to check & upgrade all casks.
46
+
47
+ - displays a confirmation prompt `[y/n]` when it attempts to re-install.
48
+ - Install latest version. (`brew cask install --force #{cask}`)
44
49
 
45
50
  ```
46
51
  % bcupgrade
@@ -55,7 +60,6 @@ atom / 1.10.2
55
60
  Upgrade 1password? [y/n] n
56
61
 
57
62
  Upgrade atom? [y/n] y
58
- remove atom
59
63
  install atom
60
64
  ==> Satisfying dependencies
61
65
  complete
@@ -70,48 +74,24 @@ complete
70
74
  🍺 atom was successfully installed!
71
75
  ```
72
76
 
73
- - Remove previous versions.
74
- `rm -rf /usr/local/Caskroom/#{cask}`
75
- - Install latest version.
76
- `brew cask install --force #{cask}`
77
+ `bcupgrade` with arguments to check & upgrade selected casks.
77
78
 
78
79
  ```
79
- % brew cask info atom
80
- atom: 1.10.2
81
- https://atom.io/
82
- /usr/local/Caskroom/atom/1.10.2 (68B)
83
- From: https://github.com/caskroom/homebrew-cask/blob/master/Casks/atom.rb
84
- ==> Name
85
- Github Atom
86
- ==> Artifacts
87
- Atom.app (app)
88
- /Applications/Atom.app/Contents/Resources/app/apm/node_modules/.bin/apm (binary)
89
- /Applications/Atom.app/Contents/Resources/app/atom.sh (binary)
80
+ % bcupgrade dropbox firefox
90
81
  ```
91
82
 
92
83
 
93
84
  ## Configuration File
94
85
 
95
- in the user's `~/.bcupgrade` (YAML syntax).
96
-
97
- If you want to ignore upgrade casks, you can add settings.
86
+ If you want to ignore upgrade casks, you can add settings in the user's `~/.bcupgrade` (YAML syntax).
98
87
 
99
88
  ```
100
89
  ignore:
101
- - omniplan1
90
+ - omniplan
102
91
  - sublime-text2
103
92
  ```
104
93
 
105
94
 
106
- ## Development
107
-
108
- After checking out the repo, run `bin/setup` to install dependencies.
109
- Then, run `rake spec` to run the tests.
110
- You can also run `bin/console` for an interactive prompt that will allow you to experiment.
111
-
112
- To install this gem onto your local machine, run `bundle exec rake install`.
113
- To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
114
-
115
95
  ## Contributing
116
96
 
117
97
  Bug reports and pull requests are welcome on GitHub at https://github.com/DriftwoodJP/bcupgrade.
data/exe/bcupgrade CHANGED
@@ -6,18 +6,24 @@ require 'readline'
6
6
 
7
7
  OptionParser.new do |opt|
8
8
  begin
9
+ options = {}
10
+ opt.on('-d', '--dry-run', 'Show output without running') do |v|
11
+ options[:dry_run] = v
12
+ end
13
+ opt.on('-r', '--remove', 'Remove previous version casks with installing') do |v|
14
+ options[:remove] = v
15
+ end
16
+ opt.on('-y', '--yes', 'Install cask without prompt') do |v|
17
+ options[:install] = v
18
+ end
9
19
  opt.on('-v', '--version', 'Show version number') do
10
20
  puts Bcupgrade::VERSION
11
21
  exit
12
22
  end
13
- opt.on('--dry-run', 'Show output without running') do
14
- opt.parse!(ARGV)
15
- Bcupgrade.run
16
- exit
17
- end
18
23
 
19
- opt.parse!(ARGV)
20
- Bcupgrade.run(true)
24
+ args = opt.parse!(ARGV)
25
+
26
+ Bcupgrade.run(options, args)
21
27
  rescue => e
22
28
  puts e.to_s
23
29
  exit
@@ -1,19 +1,21 @@
1
1
  module Bcupgrade
2
- CASKROOM_PATH = '/usr/local/Caskroom'.freeze
2
+ module BrewCask
3
+ CASKROOM_PATH = '/usr/local/Caskroom'.freeze
3
4
 
4
- def self.brew_cask_list
5
- `brew cask list`
6
- end
5
+ def self.list
6
+ `brew cask list`
7
+ end
7
8
 
8
- def self.brew_cask_info(cask)
9
- `brew cask info #{cask}`
10
- end
9
+ def self.info(cask)
10
+ `brew cask info #{cask}`
11
+ end
11
12
 
12
- def self.brew_cask_remove(cask)
13
- system "rm -rf #{CASKROOM_PATH}/#{cask}"
14
- end
13
+ def self.remove(cask)
14
+ system "rm -rf #{CASKROOM_PATH}/#{cask}"
15
+ end
15
16
 
16
- def self.brew_cask_install(cask)
17
- system "brew cask install --force #{cask}"
17
+ def self.install(cask)
18
+ system "brew cask install --force #{cask}"
19
+ end
18
20
  end
19
21
  end
@@ -0,0 +1,100 @@
1
+ require 'yaml'
2
+
3
+ module Bcupgrade
4
+ class Cask
5
+ attr_reader :installed_casks, :error_casks
6
+
7
+ def initialize(options, args)
8
+ @config = config
9
+ @options = options
10
+ @args = args.uniq
11
+ @list = upgrade_target
12
+ @installed_casks = @list[0]
13
+ @error_casks = @list[1]
14
+ end
15
+
16
+ def check_version
17
+ update_casks = []
18
+
19
+ @installed_casks.each do |name|
20
+ cask_info = BrewCask.info(name)
21
+ version_number = trim_latest_version(cask_info)
22
+
23
+ string = "#{BrewCask::CASKROOM_PATH}/#{name}/#{version_number}"
24
+ latest_version = cask_info.include?(string) ? nil : version_number
25
+
26
+ if latest_version
27
+ puts "#{name} / #{latest_version}"
28
+ update_casks.push(name)
29
+ end
30
+ end
31
+
32
+ update_casks
33
+ end
34
+
35
+ def upgrade_version(casks)
36
+ return if @options[:dry_run]
37
+
38
+ casks.each do |cask|
39
+ input = if @options[:install]
40
+ 'y'
41
+ else
42
+ Readline.readline("\nUpgrade #{cask}? [y/n] ")
43
+ end
44
+ next unless input == 'y'
45
+
46
+ if @options[:remove]
47
+ puts "remove #{cask}"
48
+ BrewCask.remove(cask)
49
+ end
50
+
51
+ puts "install #{cask}"
52
+ BrewCask.install(cask)
53
+ end
54
+ end
55
+
56
+ private
57
+
58
+ def config
59
+ file = File.join(ENV['HOME'], '.bcupgrade')
60
+ YAML.load_file(file) if File.exist?(file)
61
+ end
62
+
63
+ def upgrade_target
64
+ if @args.any?
65
+ trim_target_to_a(@args)
66
+ else
67
+ check_target = trim_target_to_a(BrewCask.list.split(/\n/))
68
+ [trim_ignore_casks(check_target[0]), check_target[1]]
69
+ end
70
+ end
71
+
72
+ def trim_target_to_a(array)
73
+ installed_casks = []
74
+ error_casks = []
75
+
76
+ array.each do |cask|
77
+ if cask.include?(' (!)')
78
+ error_casks.push(cask.delete(' (!)'))
79
+ else
80
+ installed_casks.push(cask)
81
+ end
82
+ end
83
+
84
+ [installed_casks, error_casks]
85
+ end
86
+
87
+ def trim_ignore_casks(casks)
88
+ if @config.nil?
89
+ casks
90
+ else
91
+ casks - Array(@config['ignore'])
92
+ end
93
+ end
94
+
95
+ def trim_latest_version(cask_info)
96
+ lines = cask_info.split(/\n/)
97
+ lines[0].gsub(/.+: (.+)/, '\1') if lines[0]
98
+ end
99
+ end
100
+ end
@@ -1,3 +1,3 @@
1
1
  module Bcupgrade
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
data/lib/bcupgrade.rb CHANGED
@@ -1,92 +1,30 @@
1
- require 'bcupgrade/version'
2
- require 'bcupgrade/brew_cask'
3
- require 'yaml'
1
+ require_relative 'bcupgrade/version'
2
+ require_relative 'bcupgrade/brew_cask'
3
+ require_relative 'bcupgrade/cask'
4
4
 
5
5
  module Bcupgrade
6
- def self.load_config
7
- file = File.join(ENV['HOME'], '.bcupgrade')
8
- YAML.load_file(file) if File.exist?(file)
9
- end
10
-
11
- def self.installed_casks(casks, config)
12
- if config.nil?
13
- casks
14
- else
15
- casks - Array(config['ignore'])
16
- end
17
- end
18
-
19
- def self.check_list
20
- cask_list = Bcupgrade.brew_cask_list.split("\n")
21
-
22
- installed_casks = []
23
- error_casks = []
24
- cask_list.each do |cask|
25
- if cask.include?(' (!)')
26
- error_casks.push(cask.delete(' (!)'))
27
- else
28
- installed_casks.push(cask)
29
- end
30
- end
31
-
32
- [installed_casks, error_casks]
33
- end
34
-
35
- def self.check_version(cask)
36
- cask_info = Bcupgrade.brew_cask_info(cask)
37
- lines = cask_info.split(/\n/)
38
- latest_version = if lines[0].nil?
39
- 'error'
40
- else
41
- lines[0].gsub(/.+: (.+)/, '\1')
42
- end
43
- installed_path = "#{Bcupgrade::CASKROOM_PATH}/#{cask}/#{latest_version}"
44
-
45
- cask_info.include?(installed_path) ? nil : latest_version
46
- end
47
-
48
- def self.upgrade(casks)
49
- casks.each do |cask|
50
- input = Readline.readline("\nUpgrade #{cask}? [y/n] ")
51
- next unless input == 'y'
52
- puts "remove #{cask}"
53
- Bcupgrade.brew_cask_remove(cask)
54
- puts "install #{cask}"
55
- Bcupgrade.brew_cask_install(cask)
56
- end
57
- end
58
-
59
- def self.run(option = false)
60
- config = Bcupgrade.load_config
6
+ def self.run(options, args)
7
+ cask = Cask.new(options, args)
61
8
 
62
9
  # Check cask list
63
10
  puts "\n==> Check 'brew cask list'...\n"
64
11
 
65
- cask_list = Bcupgrade.check_list
66
- installed_casks = Bcupgrade.installed_casks(cask_list[0], config)
67
- error_casks = cask_list[1]
12
+ installed_casks = cask.installed_casks
13
+ error_casks = cask.error_casks
68
14
 
69
15
  puts "#{installed_casks}\n"
70
-
71
- unless error_casks == []
16
+ if error_casks.any?
72
17
  puts "\nSkip re-install: can't found brew cask info\n#{error_casks}\n"
73
18
  end
74
19
 
75
20
  # Check cask version
76
21
  puts "\n==> Check 'brew cask info' for the latest available version...\n"
77
22
 
78
- update_casks = []
79
- installed_casks.each do |cask|
80
- latest_version = Bcupgrade.check_version(cask)
81
- if latest_version
82
- puts "#{cask} / #{latest_version}"
83
- update_casks.push(cask)
84
- end
85
- end
23
+ update_casks = cask.check_version
86
24
 
87
25
  # Upgrade cask
88
26
  if update_casks.any?
89
- Bcupgrade.upgrade(update_casks) if option
27
+ cask.upgrade_version(update_casks)
90
28
  else
91
29
  puts "\nAlready up-to-date."
92
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bcupgrade
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - DriftwoodJP
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-24 00:00:00.000000000 Z
11
+ date: 2017-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -132,6 +132,7 @@ files:
132
132
  - exe/bcupgrade
133
133
  - lib/bcupgrade.rb
134
134
  - lib/bcupgrade/brew_cask.rb
135
+ - lib/bcupgrade/cask.rb
135
136
  - lib/bcupgrade/version.rb
136
137
  homepage: https://github.com/DriftwoodJP/bcupgrade
137
138
  licenses: