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 +4 -4
- data/.rubocop.yml +6 -0
- data/CHANGELOG.md +9 -0
- data/Gemfile.lock +1 -1
- data/README.md +7 -0
- data/bin/binbundle +30 -9
- data/lib/binbundle/gem_bins.rb +26 -2
- data/lib/binbundle/gem_list.rb +26 -11
- data/lib/binbundle/version.rb +1 -1
- data/src/_README.md +7 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 593e189840e9f90dc770daa8af1bded80d6a732cf9f7e35589b86314b884f4fa
|
4
|
+
data.tar.gz: ae7314de2c67a750210a57462fdc64fbd3ba61fa99f0a2a7393747dbc20b2c68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d4e06a1f4063f3b92a273380d616681b069b41e024047fc6974276dabd767b4fadef660ad38d7bc62dd510ed0043906a0e20125d5172e81b44e9853b4a1d876
|
7
|
+
data.tar.gz: 870dffb7b79c27871ab90bd7f5875dd9dbf4952ff3db254d44d12d73b807f65901a238b2d42fdaeb8f96e52aa95569c4bf1bd6937b0a24bf292548301b89e70b
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
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('--
|
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('
|
22
|
-
options[:
|
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
|
-
|
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[:
|
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
|
data/lib/binbundle/gem_bins.rb
CHANGED
@@ -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
|
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
|
-
|
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
|
data/lib/binbundle/gem_list.rb
CHANGED
@@ -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
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
data/lib/binbundle/version.rb
CHANGED
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.
|