binbundle 1.0.8 → 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c0b2748f2e8c24eec90dc2856e26ddcb5844482d976ea4cefd6147d88821d65f
4
- data.tar.gz: 3192461bfa06f6eb6cfdbbbd7f402032c36fd7eda67df87b91a08fb69e7e6e5b
3
+ metadata.gz: 593e189840e9f90dc770daa8af1bded80d6a732cf9f7e35589b86314b884f4fa
4
+ data.tar.gz: ae7314de2c67a750210a57462fdc64fbd3ba61fa99f0a2a7393747dbc20b2c68
5
5
  SHA512:
6
- metadata.gz: 6723f148c5cc7f64c1220863d77cdfb74c65ff918f3d91098419fb23660d0cf1cf07d15be626559a36d1649b6a0a59f12481b74bebd65a3bfd0fd33ce6dd46f0
7
- data.tar.gz: c89ceb0a85a1ba3d2e7f7e404eb06c5221d2a85e83f4f8f7627b99c47efd0cdfff5572fed1fa98a37182b12f5cd962636465f03601f252081ac4b739870a7156
6
+ metadata.gz: 9d4e06a1f4063f3b92a273380d616681b069b41e024047fc6974276dabd767b4fadef660ad38d7bc62dd510ed0043906a0e20125d5172e81b44e9853b4a1d876
7
+ data.tar.gz: 870dffb7b79c27871ab90bd7f5875dd9dbf4952ff3db254d44d12d73b807f65901a238b2d42fdaeb8f96e52aa95569c4bf1bd6937b0a24bf292548301b89e70b
data/.rubocop.yml CHANGED
@@ -20,6 +20,12 @@ Layout/LineLength:
20
20
  Metrics/MethodLength:
21
21
  Max: 40
22
22
 
23
+ Metrics/BlockLength:
24
+ Max: 40
25
+
26
+ Metrics/ClassLength:
27
+ Max: 200
28
+
23
29
  Metrics/CyclomaticComplexity:
24
30
  Max: 10
25
31
 
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ### 1.0.9
2
+
3
+ 2024-08-02 10:42
4
+
5
+ #### NEW
6
+
7
+ - `binbundle gem for BIN` will show what gem is responsible for a binary
8
+ - `binbundle bins for GEM` will show what binaries a gem installs
9
+
1
10
  ### 1.0.8
2
11
 
3
12
  2024-08-02 09:23
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- binbundle (1.0.7)
4
+ binbundle (1.0.9)
5
5
  tty-spinner (~> 0.9)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -42,10 +42,17 @@ Usage: binbundle [options] [bundle|install]
42
42
  -s, --sudo Install gems with sudo
43
43
  -u, --user-install Use --user-install to install gems
44
44
  -f, --file FILE Output to alternative filename (default Binfile)
45
+ -l, --local Use installed gems instead of Binfile for gem_for and bins_for
45
46
  -v, --version Display version
46
47
  -h, --help Display this screen
47
48
  ```
48
49
 
50
+ #### Info commands
51
+
52
+ You can retrieve some basic info about gems and their binaries using `binbundle gem for BIN` or `binbundle bins for GEM`. This will read `Binfile` or any file specified by `--file` and return the requested info, either the gem associated with the given binary (BIN), or the binaries associated with the given gem name (GEM).
53
+
54
+ Use either info command with `--local` to parse installed gems rather than a Binfile.
55
+
49
56
  ### Recommendations
50
57
 
51
58
  I recommend using Binbundle along with a tool like Dotfiles. Commit your bundle to a repo that you can easily clone to a new machine and then make `gem install binbundle` and `binbundle install ~/dotfiles/Binfile` part of your restore process.
data/bin/binbundle CHANGED
@@ -4,9 +4,12 @@
4
4
  require_relative '../lib/binbundle'
5
5
 
6
6
  options = {
7
+ bin_for: nil,
7
8
  dry_run: false,
8
9
  file: 'Binfile',
10
+ gem_for: nil,
9
11
  include_version: true,
12
+ local: false,
10
13
  sudo: false,
11
14
  user_install: false
12
15
  }
@@ -14,12 +17,20 @@ options = {
14
17
  optparse = OptionParser.new do |opts|
15
18
  opts.banner = "Usage: #{File.basename(__FILE__)} [options] [bundle|install]"
16
19
 
17
- opts.on('--[no-]versions', 'Include version info in output (default true)') do |opt|
20
+ opts.on('--dry-run', 'Output to STDOUT instead of file') do
21
+ options[:dry_run] = true
22
+ end
23
+
24
+ opts.on('-f', '--file FILE', 'Output to alternative filename (default Binfile)') do |opt|
25
+ options[:file] = opt
26
+ end
27
+
28
+ opts.on('--[no-]versions', 'Include version info in output or restore (default true)') do |opt|
18
29
  options[:include_version] = opt
19
30
  end
20
31
 
21
- opts.on('--dry-run', 'Output to STDOUT instead of file') do
22
- options[:dry_run] = true
32
+ opts.on('-l', '--local', 'Use installed gems instead of Binfile for gem_for and bins_for') do
33
+ options[:local] = true
23
34
  end
24
35
 
25
36
  opts.on('-s', '--sudo', 'Install gems with sudo') do
@@ -30,10 +41,6 @@ optparse = OptionParser.new do |opts|
30
41
  options[:user_install] = true
31
42
  end
32
43
 
33
- opts.on('-f', '--file FILE', 'Output to alternative filename (default Binfile)') do |opt|
34
- options[:file] = opt
35
- end
36
-
37
44
  opts.on('-v', '--version', 'Display version') do
38
45
  puts "#{File.basename(__FILE__)} v#{Binbundle::VERSION}"
39
46
  Process.exit 0
@@ -54,9 +61,23 @@ end
54
61
 
55
62
  gb = Binbundle::GemBins.new(options)
56
63
 
57
- options[:install] = true if ARGV.count.positive? && ARGV[0] =~ /^(inst|rest)/
64
+ if ARGV.count.positive?
65
+ subcommand = ARGV.shift
66
+ params = ARGV.join(' ').sub(/ *for */, '')
67
+
68
+ case subcommand
69
+ when /^(inst|rest)/
70
+ options[:install] = true
71
+ when /^gem/
72
+ options[:gem_for] = params
73
+ when /^bin/
74
+ options[:bin_for] = params
75
+ end
76
+ end
58
77
 
59
- if options[:install]
78
+ if options[:gem_for] || options[:bin_for]
79
+ puts gb.info(options)
80
+ elsif options[:install]
60
81
  gb.install
61
82
  else
62
83
  gb.generate
@@ -17,6 +17,26 @@ module Binbundle
17
17
  @local_gems = local_gems.delete_if { |_, specs| specs.delete_if { |spec| spec.executables.empty? }.empty? }
18
18
  end
19
19
 
20
+ def info(options)
21
+ unless File.exist?(@file) || options[:local]
22
+ puts "File #{@file} not found"
23
+ Process.exit 1
24
+ end
25
+
26
+ contents = if options[:local]
27
+ bins_to_s
28
+ else
29
+ IO.read(@file)
30
+ end
31
+
32
+ gem_list = GemList.new(contents, include_version: @include_version)
33
+ if options[:gem_for]
34
+ gem_list.gem_for_bin(options[:gem_for])
35
+ elsif options[:bin_for]
36
+ gem_list.bins_for_gem(options[:bin_for])
37
+ end
38
+ end
39
+
20
40
  def install
21
41
  unless File.exist?(@file)
22
42
  puts "File #{@file} not found"
@@ -81,7 +101,7 @@ module Binbundle
81
101
  "# Executables: #{attrs[:bins].join(', ')}\n#{sudo}gem install #{ui}#{gem}#{ver}"
82
102
  end
83
103
 
84
- def generate
104
+ def bins_to_s
85
105
  gems_with_bins = {}
86
106
 
87
107
  @local_gems.each do |g, specs|
@@ -90,7 +110,11 @@ module Binbundle
90
110
  gems_with_bins[g] = { version: versions.max, bins: bins.sort.uniq }
91
111
  end
92
112
 
93
- output = gems_with_bins.map { |gem, attrs| gem_command(gem, attrs) }.join("\n\n")
113
+ gems_with_bins.map { |gem, attrs| gem_command(gem, attrs) }.join("\n\n")
114
+ end
115
+
116
+ def generate
117
+ output = bins_to_s
94
118
 
95
119
  if @dry_run
96
120
  puts output
@@ -8,39 +8,54 @@ module Binbundle
8
8
  def initialize(contents, include_version: true)
9
9
  @contents = contents
10
10
  @include_version = include_version
11
- @gem_list = gem_list
12
11
  end
13
12
 
14
13
  def gem_list
15
- @gem_list ||= @contents.split("\n")
16
- .delete_if { |line| line.strip.empty? || line =~ /^#/ }
17
- .each_with_object([]) do |l, arr|
18
- rx = /^(?x)(?:sudo\s)?gem\sinstall\s(?:--user-install\s)?
19
- (?<gem>\S+)(?:\s(?:-v|--version)\s'(?<version>[0-9.]+)')?/
20
- m = l.match(rx)
21
- arr << { gem: m['gem'], version: m['version'] }
14
+ return @gem_list if @gem_list
15
+
16
+ rx = /(?mix)(?:\#\sExecutables:\s(?<bins>[\S\s,]+?)\n)?(?:sudo\s)?gem\sinstall
17
+ \s(?:--user-install\s)?
18
+ (?<gem>\S+)(?:\s(?:-v|--version)\s'(?<version>[0-9.]+)')?/
19
+ @gem_list = []
20
+ @contents.to_enum(:scan, rx).map { Regexp.last_match }.each do |m|
21
+ @gem_list << { gem: m['gem'], bins: m['bins']&.split(', '), version: m['version'] }
22
22
  end
23
+ @gem_list
23
24
  end
24
25
 
25
26
  def sudo
26
- @gem_list.map do |gem|
27
+ gem_list.map do |gem|
27
28
  version = @include_version && gem[:version] ? " -v '#{gem[:version]}'" : ''
28
29
  "sudo gem install #{gem[:gem]}#{version}"
29
30
  end
30
31
  end
31
32
 
32
33
  def user_install
33
- @gem_list.map do |gem|
34
+ gem_list.map do |gem|
34
35
  version = @include_version && gem[:version] ? " -v '#{gem[:version]}'" : ''
35
36
  "gem install --user-install #{gem[:gem]}#{version}"
36
37
  end
37
38
  end
38
39
 
39
40
  def normal_install
40
- @gem_list.map do |gem|
41
+ gem_list.map do |gem|
41
42
  version = @include_version && gem[:version] ? " -v '#{gem[:version]}'" : ''
42
43
  "gem install #{gem[:gem]}#{version}"
43
44
  end
44
45
  end
46
+
47
+ def gem_for_bin(bin)
48
+ m = gem_list.select { |gem| gem[:bins].include?(bin) }.first
49
+ return "Gem for #{bin} not found" unless m
50
+
51
+ m[:gem]
52
+ end
53
+
54
+ def bins_for_gem(gem)
55
+ m = gem_list.select { |g| g[:gem] == gem }.first
56
+ return "Gem #{gem} not found" unless m
57
+
58
+ m[:bins] ? m[:bins].join("\n") : 'Missing info'
59
+ end
45
60
  end
46
61
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Binbundle
4
- VERSION = '1.0.8'
4
+ VERSION = '1.0.9'
5
5
  end
data/src/_README.md CHANGED
@@ -42,10 +42,17 @@ Usage: binbundle [options] [bundle|install]
42
42
  -s, --sudo Install gems with sudo
43
43
  -u, --user-install Use --user-install to install gems
44
44
  -f, --file FILE Output to alternative filename (default Binfile)
45
+ -l, --local Use installed gems instead of Binfile for gem_for and bins_for
45
46
  -v, --version Display version
46
47
  -h, --help Display this screen
47
48
  ```
48
49
 
50
+ #### Info commands
51
+
52
+ You can retrieve some basic info about gems and their binaries using `binbundle gem for BIN` or `binbundle bins for GEM`. This will read `Binfile` or any file specified by `--file` and return the requested info, either the gem associated with the given binary (BIN), or the binaries associated with the given gem name (GEM).
53
+
54
+ Use either info command with `--local` to parse installed gems rather than a Binfile.
55
+
49
56
  ### Recommendations
50
57
 
51
58
  I recommend using Binbundle along with a tool like Dotfiles. Commit your bundle to a repo that you can easily clone to a new machine and then make `gem install binbundle` and `binbundle install ~/dotfiles/Binfile` part of your restore process.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: binbundle
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra