all-gem 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: df4b9002e4c022b2aca28431f7a8c4ab4d41fb9545926f023872c8af3c34ca6e
4
- data.tar.gz: 5cb10b7701033331b1499060aa21f51eb1278e0a8ad7f7279ddf9805645ce135
3
+ metadata.gz: 2e51778b01d35295b44dc8a8dce68033785a5fc6df589b8ef7362f2213a97fff
4
+ data.tar.gz: a5482e7f7aaecfeeb0b9f39fc578a918545a5544a1b4e816026a29fc83b976a1
5
5
  SHA512:
6
- metadata.gz: 29e919012bd142c82fe01f057385a1b00630592c0126a539ac6688dc3263917dd7732a8d03f20f26a8e7f0a9a5dbdd4b62709d9382ec30951ba162d40703a1a9
7
- data.tar.gz: 6a19d9fc904954947bcc19a775c6b4211608c25c75fe9382a4226777bfbfd80cf04ccdd09a254783765605e6c46118b2732504431472b4d3542805e16443b429
6
+ metadata.gz: dfad772ebdecf5df0ef1d0b492ee555e61c18501ab89706f338e26d867ac2efd9c10d8bde480ae1d282ca58f91be96a347a07dc670e17411bffa8bac08bd3ab6
7
+ data.tar.gz: aa3ddcc0d32641574efe10ec46947fc0b7e815b42f7185b442098cc76d967d6c813e3c95dba4976f3f24a49a02443bc3a52987cacffe6e7fb18ad722c17eb6ff
data/Gemfile CHANGED
@@ -7,3 +7,6 @@ gemspec
7
7
 
8
8
  gem "rake"
9
9
  gem 'steep'
10
+ gem 'activesupport', '< 7' # https://github.com/soutaro/steep/issues/466
11
+
12
+ gem 'test-unit'
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Masataka Pocke Kuwabara
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/Rakefile CHANGED
@@ -1,4 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "bundler/gem_tasks"
4
- task default: %i[]
4
+ require "rake/testtask"
5
+
6
+ task default: %i[steep test]
7
+
8
+ Rake::TestTask.new(:test) do |t|
9
+ t.libs << "test"
10
+ t.libs << "lib"
11
+ t.test_files = FileList["test/**/*_test.rb"]
12
+ end
13
+
14
+ task :steep do
15
+ sh 'steep check'
16
+ end
data/all-gem.gemspec CHANGED
@@ -7,6 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.version = AllGem::VERSION
8
8
  spec.authors = ["Masataka Pocke Kuwabara"]
9
9
  spec.email = ["kuwabara@pocke.me"]
10
+ spec.license = 'MIT'
10
11
 
11
12
  spec.summary = "Run various versions of command provided by gem"
12
13
  spec.description = "Run various versions of command provided by gem"
data/lib/all-gem/cli.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'optparse'
2
+ require 'open3'
2
3
 
3
4
  module AllGem
4
5
  class CLI
@@ -41,12 +42,7 @@ module AllGem
41
42
  versions = filter_by_level(versions, opts)
42
43
  install! spec, versions
43
44
 
44
- # TODO: omit the same output
45
- # TODO: handle exit status
46
- versions.each do |v|
47
- stdout.puts "#{command}-#{v}"
48
- __skip__ = system(command, "_#{v}_", *argv[1..])
49
- end
45
+ execute_and_print argv, versions
50
46
  end
51
47
 
52
48
  private
@@ -56,7 +52,7 @@ module AllGem
56
52
  @op = OptionParser.new
57
53
 
58
54
  op.banner = <<~BANNER
59
- Usage: all-ruby [all-ruby options] COMMAND [command options]
55
+ Usage: all-gem [all-gem options] COMMAND [command options]
60
56
  BANNER
61
57
 
62
58
  op.on('--remote', 'Install the gems if it does not exist in the local') { opts.remote = true }
@@ -69,6 +65,50 @@ module AllGem
69
65
  # op.on('--pre') # TODO: consider the API
70
66
  end
71
67
 
68
+ def execute_and_print(argv, versions)
69
+ command = argv[0]
70
+
71
+ # @type var prev: [String?, Process::Status?]
72
+ prev = [nil, nil]
73
+ prev_idx = -1
74
+ versions.each.with_index do |v, idx|
75
+ no_bundler do
76
+ output, status = Open3.capture2e(command, "_#{v}_", *(argv[1..] or raise))
77
+ if prev != [output, status]
78
+ if prev_idx != idx-1
79
+ print_result command, versions, idx-1, (prev[0] or raise), (prev[1] or raise)
80
+ end
81
+ print_result command, versions, idx, output, status
82
+
83
+ prev_idx = idx
84
+ else
85
+ stdout.puts '...' if prev_idx == idx-1
86
+ end
87
+
88
+ __skip__ = prev = [output, status]
89
+ end
90
+ end
91
+
92
+ if prev_idx != versions.size-1
93
+ print_result command, versions, versions.size-1, (prev[0] or raise), (prev[1] or raise)
94
+ end
95
+ end
96
+
97
+ def print_result(command, versions, idx, output, status)
98
+ exit_status_indent = 8
99
+ longest_version = versions.max_by { |v| command.size + '-'.size + v.to_s.size } or raise
100
+ output_indent = command.size + '-'.size + longest_version.to_s.size + ' '.size
101
+
102
+ version = versions[idx]
103
+ label = "#{command}-#{version}"
104
+
105
+ stdout.print label
106
+ lines = output.lines
107
+ stdout.puts "#{' ' * (output_indent - label.size)}#{lines[0]}"
108
+ stdout.puts (lines[1..] or raise).map { |line| "#{' ' * output_indent}#{line}"}
109
+ stdout.puts "#{' ' * exit_status_indent}exit #{status.exitstatus}" unless status.success?
110
+ end
111
+
72
112
  def gemspec_from_command(command)
73
113
  spec = Gem::Specification.find { |s| s.executables.include?(command) }
74
114
  # TODO: did you mean
@@ -103,7 +143,9 @@ module AllGem
103
143
  targets = (versions - installed).map { |v| "#{spec.name}:#{v}" }
104
144
  return if targets.empty?
105
145
 
106
- __skip__ = system('gem', 'install', *targets, exception: true)
146
+ no_bundler do
147
+ __skip__ = system('gem', 'install', *targets, '--conservative', exception: true)
148
+ end
107
149
  end
108
150
 
109
151
  def filter_by_level(versions, opts)
@@ -112,5 +154,15 @@ module AllGem
112
154
  n = { major: 0, minor: 1, patch: 2 }[opts.level]
113
155
  versions.group_by { |v| v.segments[0..n] }.map { |_, vs| vs.max or raise }
114
156
  end
157
+
158
+ def no_bundler(&block)
159
+ if defined?(Bundler)
160
+ Bundler.with_unbundled_env do
161
+ block.call
162
+ end
163
+ else
164
+ block.call
165
+ end
166
+ end
115
167
  end
116
168
  end
@@ -1,3 +1,3 @@
1
1
  module AllGem
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -15,7 +15,7 @@ module AllGem
15
15
  end
16
16
 
17
17
  attr_reader stdout: IO
18
- attr_reader sderr: IO
18
+ attr_reader stderr: IO
19
19
  attr_reader stdin: IO
20
20
  attr_reader opts: Options
21
21
  attr_reader op: OptionParser
@@ -30,7 +30,9 @@ module AllGem
30
30
 
31
31
  def set_optparse: () -> void
32
32
 
33
- def help: () -> String
33
+ def execute_and_print: (Array[String] argv, Array[Gem::Version]) -> void
34
+
35
+ def print_result: (String command, Array[Gem::Version], Integer index, String output, Process::Status) -> void
34
36
 
35
37
  def gemspec_from_command: (String command) -> Gem::Specification
36
38
 
@@ -43,5 +45,7 @@ module AllGem
43
45
  def install!: (Gem::Specification, Array[Gem::Version]) -> void
44
46
 
45
47
  def filter_by_level: (Array[Gem::Version], Options) -> Array[Gem::Version]
48
+
49
+ def no_bundler: [T] () { () -> T } -> T
46
50
  end
47
51
  end
@@ -0,0 +1,3 @@
1
+ module Bundler
2
+ def self.with_unbundled_env: [T] () { () -> T } -> T
3
+ end
@@ -0,0 +1,3 @@
1
+ module Open3
2
+ def self.capture2e: (*String) -> [String, Process::Status]
3
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: all-gem
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
  - Masataka Pocke Kuwabara
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-03 00:00:00.000000000 Z
11
+ date: 2022-01-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Run various versions of command provided by gem
14
14
  email:
@@ -19,6 +19,7 @@ extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
21
  - Gemfile
22
+ - LICENSE
22
23
  - README.md
23
24
  - Rakefile
24
25
  - Steepfile
@@ -29,10 +30,13 @@ files:
29
30
  - lib/all-gem.rb
30
31
  - lib/all-gem/cli.rb
31
32
  - lib/all-gem/version.rb
32
- - sig/all/gem.rbs
33
+ - sig/all-gem.rbs
34
+ - sig_internal/bundler.rbs
35
+ - sig_internal/open3.rbs
33
36
  - sig_internal/rubygems.rbs
34
37
  homepage: https://github.com/pocke/all-gem
35
- licenses: []
38
+ licenses:
39
+ - MIT
36
40
  metadata:
37
41
  homepage_uri: https://github.com/pocke/all-gem
38
42
  source_code_uri: https://github.com/pocke/all-gem