gemx 0.1.0 → 0.2.0

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: dcfb924881fd236592853cd2e23cd191b5bacfd639d95edd1ee05128d8a5e6eb
4
- data.tar.gz: b0d4b606b96ed30e36db5c6377ef63d0452691a0c3f9c3ed2f905525fcc11c7d
3
+ metadata.gz: cbc55303df14243474da3f5eefcfc219e5dffe15c7e6f1db67d20f839b9e1082
4
+ data.tar.gz: 3db245cc4fc12d4e9d5459c6a588d21caa946cb78a374a6ac6fee2328ed52d64
5
5
  SHA512:
6
- metadata.gz: d23882aef1d64ee8f1013f3f45ae26ba73092c94cfc52795cacd5812ccea76e13e7c58e6a124677c85148c06e3817c08b0e30022569875d94ae076910c061713
7
- data.tar.gz: 67dd0e4ce8e97910f2e775bd90dde474fd79c14e968762c98ef3526288d285642377e2a42ea75303fcff24a25274a06913b7681e6ede59b6742a94468456ca0a
6
+ metadata.gz: 1c2839f4f755f927448056c687275fed3f80c15011ae7e9855d85c7fb0bb570b3e894b5be6428660b2ae798d0d90a387f1131dfedd05f3bb44762d01ffd7e4cb
7
+ data.tar.gz: ea6df1cbee98d7eef90d307823d82d8dbc14c44a8d37d1df85d8d6ce5db2bc8cdb3d609d88e263637c72f189f4705a112ba04afdd04c4e3794369c068045bd66
@@ -1 +1,7 @@
1
1
  inherit_from: .rubocop_todo.yml
2
+
3
+ Metrics:
4
+ Enabled: false
5
+
6
+ Metrics/LineLength:
7
+ Enabled: true
@@ -1,16 +1,7 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2017-12-01 15:42:22 -0600 using RuboCop version 0.49.1.
3
+ # on 2018-04-10 20:20:02 -0700 using RuboCop version 0.51.0.
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
7
7
  # versions of RuboCop, may require this file to be generated again.
8
-
9
- # Offense count: 2
10
- Metrics/AbcSize:
11
- Max: 38
12
-
13
- # Offense count: 2
14
- # Configuration parameters: CountComments.
15
- Metrics/MethodLength:
16
- Max: 25
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
+ load File.expand_path('../../exe/gemx', __FILE__)
@@ -1,10 +1,7 @@
1
- lib = File.expand_path('../lib', __FILE__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require 'gemx/version'
4
-
5
1
  Gem::Specification.new do |spec|
6
2
  spec.name = 'gemx'
7
- spec.version = GemX::VERSION
3
+ spec.version = File.read(File.expand_path('../VERSION', __FILE__))
4
+ .strip.freeze
8
5
  spec.authors = ['Samuel Giddins']
9
6
  spec.email = ['segiddins@segiddins.me']
10
7
 
@@ -5,7 +5,15 @@ require 'rubygems'
5
5
 
6
6
  # Execute a command that comes from a gem
7
7
  module GemX
8
- X = Struct.new(:verbose, :gem_name, :requirements, :executable, :arguments)
8
+ X = Struct.new(
9
+ :gem_name,
10
+ :requirements,
11
+ :executable,
12
+ :arguments,
13
+ :conservative,
14
+ :verbose
15
+ )
16
+
9
17
  # The eXecutable part of this gem
10
18
  class X
11
19
  def install_if_needed
@@ -71,7 +79,7 @@ module GemX
71
79
  opts.version = VERSION
72
80
  opts.banner = 'Usage: gemx [options --] command'
73
81
 
74
- opts.on('-v', '--[no-]verbose', 'Run verbosely') do |v|
82
+ opts.on_tail('-v', '--[no-]verbose', 'Run verbosely') do |v|
75
83
  options.verbose = v
76
84
  end
77
85
 
@@ -84,20 +92,53 @@ module GemX
84
92
  'Run the gem with the given requirement') do |r|
85
93
  options.requirements.concat [r]
86
94
  end
95
+
96
+ opts.on('--pre',
97
+ 'Allow resolving pre-release versions of the gem') do |_r|
98
+ options.requirements.concat ['>= 0.a']
99
+ end
100
+
101
+ opts.on('-c', '--[no-]conservative',
102
+ 'Prefer the most recent installed version, ' \
103
+ 'rather than the latest version overall') do |c|
104
+ options.conservative = c
105
+ end
106
+ end
107
+
108
+ opt_parse.order!(args) do |v|
109
+ # put the non-option back at the front of the list of arguments
110
+ args.unshift(v)
111
+
112
+ # stop parsing once we hit the first non-option,
113
+ # so you can call `gemx rails --version` and it prints the rails
114
+ # version rather than gemx's
115
+ break
87
116
  end
88
- opt_parse.parse!(args) if args.first && args.first.start_with?('-')
117
+
89
118
  abort(opt_parse.help) if args.empty?
119
+
90
120
  options.executable = args.shift
91
121
  options.gem_name ||= options.executable
92
122
  options.arguments = args
123
+ options.requirements.requirements.tap(&:uniq).delete(['>=', Gem::Version.new('0')])
124
+
93
125
  options
94
126
  end
95
127
 
96
128
  def self.run!(argv)
97
- parse!(argv).tap do |options|
98
- options.install_if_needed
99
- options.load!
129
+ parse!(argv).run!
130
+ end
131
+
132
+ def run!
133
+ print_command if verbose
134
+ if conservative
135
+ install_if_needed
136
+ else
137
+ install
138
+ activate!
100
139
  end
140
+
141
+ load!
101
142
  end
102
143
 
103
144
  private
@@ -115,10 +156,36 @@ module GemX
115
156
  home = File.join(home, 'gemx')
116
157
  Gem.use_paths(home, Gem.path + [home])
117
158
  with_rubygems_config do
118
- Gem.install(gem_name, requirements)
159
+ suppress_always_install do
160
+ Gem.install(gem_name, requirements)
161
+ end
119
162
  end
120
163
  rescue StandardError => e
121
164
  abort "Installing #{dependency_to_s} failed:\n#{e.to_s.gsub(/^/, "\t")}"
122
165
  end
166
+
167
+ def print_command
168
+ puts "running gemx with:\n"
169
+ opts = to_h.reject { |_, v| v.nil? }
170
+ max_length = opts.map { |k, _| k.size }.max
171
+ opts.each do |k, v|
172
+ next if v.nil?
173
+ puts "\t#{k.to_s.rjust(max_length)}: #{v} "
174
+ end
175
+ puts
176
+ end
177
+
178
+ def suppress_always_install
179
+ name = :always_install
180
+ cls = ::Gem::Resolver::InstallerSet
181
+ method = cls.instance_method(name)
182
+ cls.define_method(name) { [] }
183
+
184
+ begin
185
+ yield
186
+ ensure
187
+ cls.define_method(name, method)
188
+ end
189
+ end
123
190
  end
124
191
  end
@@ -1,3 +1,4 @@
1
1
  module GemX
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = File.read(File.expand_path('../../../VERSION', __FILE__))
3
+ .strip.freeze
3
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gemx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Giddins
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-12-11 00:00:00.000000000 Z
11
+ date: 2018-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -84,7 +84,9 @@ files:
84
84
  - LICENSE.txt
85
85
  - README.md
86
86
  - Rakefile
87
+ - VERSION
87
88
  - bin/console
89
+ - bin/gemx
88
90
  - bin/rake
89
91
  - bin/rspec
90
92
  - bin/rubocop
@@ -113,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
115
  version: 2.6.10
114
116
  requirements: []
115
117
  rubyforge_project:
116
- rubygems_version: 2.7.0
118
+ rubygems_version: 2.7.6
117
119
  signing_key:
118
120
  specification_version: 4
119
121
  summary: Automagically execute commands that come in gem form