all-gem 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +9 -0
- data/README.md +49 -0
- data/Rakefile +4 -0
- data/Steepfile +13 -0
- data/all-gem.gemspec +36 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/exe/all-gem +11 -0
- data/lib/all-gem/cli.rb +116 -0
- data/lib/all-gem/version.rb +3 -0
- data/lib/all-gem.rb +5 -0
- data/sig/all/gem.rbs +47 -0
- data/sig_internal/rubygems.rbs +33 -0
- metadata +58 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: df4b9002e4c022b2aca28431f7a8c4ab4d41fb9545926f023872c8af3c34ca6e
|
4
|
+
data.tar.gz: 5cb10b7701033331b1499060aa21f51eb1278e0a8ad7f7279ddf9805645ce135
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 29e919012bd142c82fe01f057385a1b00630592c0126a539ac6688dc3263917dd7732a8d03f20f26a8e7f0a9a5dbdd4b62709d9382ec30951ba162d40703a1a9
|
7
|
+
data.tar.gz: 6a19d9fc904954947bcc19a775c6b4211608c25c75fe9382a4226777bfbfd80cf04ccdd09a254783765605e6c46118b2732504431472b4d3542805e16443b429
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# all-gem
|
2
|
+
|
3
|
+
all-gem runs various versions of command provided by gem.
|
4
|
+
|
5
|
+
It was inspired by [all-ruby](https://github.com/akr/all-ruby).
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'all-gem'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install all-gem
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Example:
|
26
|
+
|
27
|
+
```bash
|
28
|
+
# Execute `rbs --version` command with all installed versions of rbs gem
|
29
|
+
$ all-gem rbs --version
|
30
|
+
|
31
|
+
# Execute `rbs --version` command with all versions of rbs gem
|
32
|
+
# It installs gems before execution if it is not installed
|
33
|
+
$ all-gem --remote rbs --version
|
34
|
+
|
35
|
+
# Execute `rbs --version` command with all latest major versions of rbs gem
|
36
|
+
$ all-gem --remote --major rbs --version
|
37
|
+
```
|
38
|
+
|
39
|
+
See the result of `all-gem help`
|
40
|
+
|
41
|
+
## Development
|
42
|
+
|
43
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
44
|
+
|
45
|
+
To install this gem onto your local machine, run `bundle exec rake install`. 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
46
|
+
|
47
|
+
## Contributing
|
48
|
+
|
49
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/pocke/all-gem.
|
data/Rakefile
ADDED
data/Steepfile
ADDED
data/all-gem.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/all-gem/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "all-gem"
|
7
|
+
spec.version = AllGem::VERSION
|
8
|
+
spec.authors = ["Masataka Pocke Kuwabara"]
|
9
|
+
spec.email = ["kuwabara@pocke.me"]
|
10
|
+
|
11
|
+
spec.summary = "Run various versions of command provided by gem"
|
12
|
+
spec.description = "Run various versions of command provided by gem"
|
13
|
+
spec.homepage = "https://github.com/pocke/all-gem"
|
14
|
+
spec.required_ruby_version = ">= 2.6.0"
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
18
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
24
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
25
|
+
end
|
26
|
+
end
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
# Uncomment to register a new dependency of your gem
|
32
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
33
|
+
|
34
|
+
# For more information and examples about making a new gem, check out our
|
35
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
36
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "all/gem"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/all-gem
ADDED
data/lib/all-gem/cli.rb
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
module AllGem
|
4
|
+
class CLI
|
5
|
+
class Error < StandardError
|
6
|
+
attr_reader :status
|
7
|
+
|
8
|
+
def initialize(message, status = 1)
|
9
|
+
super(message)
|
10
|
+
@status = status
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class Options
|
15
|
+
attr_accessor :remote, :since, :level
|
16
|
+
|
17
|
+
def initialize
|
18
|
+
@remote = false
|
19
|
+
@since = nil
|
20
|
+
@level = :all
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
attr_reader :stdout, :stderr, :stdin, :op, :opts
|
25
|
+
|
26
|
+
def initialize(stdout:, stderr:, stdin:)
|
27
|
+
@stdout = stdout
|
28
|
+
@stderr = stderr
|
29
|
+
@stdin = stdin
|
30
|
+
|
31
|
+
set_optparse
|
32
|
+
end
|
33
|
+
|
34
|
+
def run(argv)
|
35
|
+
argv = @op.order(argv)
|
36
|
+
|
37
|
+
command = argv[0] or raise Error.new("COMMAND is not specified.\n\n" + op.help)
|
38
|
+
spec = gemspec_from_command(command)
|
39
|
+
|
40
|
+
versions = versions_of(spec, opts)
|
41
|
+
versions = filter_by_level(versions, opts)
|
42
|
+
install! spec, versions
|
43
|
+
|
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
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def set_optparse
|
55
|
+
@opts = Options.new
|
56
|
+
@op = OptionParser.new
|
57
|
+
|
58
|
+
op.banner = <<~BANNER
|
59
|
+
Usage: all-ruby [all-ruby options] COMMAND [command options]
|
60
|
+
BANNER
|
61
|
+
|
62
|
+
op.on('--remote', 'Install the gems if it does not exist in the local') { opts.remote = true }
|
63
|
+
op.on('--since VERSION', 'Run only versions since specified one') { |v| opts.since = Gem::Version.new(v) }
|
64
|
+
op.on('--major', 'Run only each major version') { opts.level = :major }
|
65
|
+
op.on('--minor', 'Run only each minor version') { opts.level = :minor }
|
66
|
+
op.on('--patch', 'Run only each patch version') { opts.level = :patch }
|
67
|
+
op.on('--version', 'Display all-ruby version') { stdout.puts "all-gem-#{AllGem::VERSION}"; exit 0 }
|
68
|
+
# op.on('--dir') # TODO: consider the API, make and cd to a directory
|
69
|
+
# op.on('--pre') # TODO: consider the API
|
70
|
+
end
|
71
|
+
|
72
|
+
def gemspec_from_command(command)
|
73
|
+
spec = Gem::Specification.find { |s| s.executables.include?(command) }
|
74
|
+
# TODO: did you mean
|
75
|
+
spec or raise Error.new("Could not find #{command} as an executable file")
|
76
|
+
end
|
77
|
+
|
78
|
+
def versions_of(spec, opts)
|
79
|
+
versions = local_versions(spec)
|
80
|
+
versions.concat remote_versions(spec) if opts.remote
|
81
|
+
|
82
|
+
versions.uniq!
|
83
|
+
versions.sort!
|
84
|
+
|
85
|
+
since = opts.since
|
86
|
+
versions = versions.select { |v| since <= v } if since
|
87
|
+
|
88
|
+
versions
|
89
|
+
end
|
90
|
+
|
91
|
+
def remote_versions(spec)
|
92
|
+
f = Gem::SpecFetcher.fetcher
|
93
|
+
f.detect(:released) { |tuple| tuple.name == spec.name }.map { |arr| arr[0].version }
|
94
|
+
end
|
95
|
+
|
96
|
+
def local_versions(spec)
|
97
|
+
Gem::Specification.select { |s| s.name == spec.name }.map { |s| s.version }
|
98
|
+
end
|
99
|
+
|
100
|
+
def install!(spec, versions)
|
101
|
+
installed = local_versions(spec)
|
102
|
+
|
103
|
+
targets = (versions - installed).map { |v| "#{spec.name}:#{v}" }
|
104
|
+
return if targets.empty?
|
105
|
+
|
106
|
+
__skip__ = system('gem', 'install', *targets, exception: true)
|
107
|
+
end
|
108
|
+
|
109
|
+
def filter_by_level(versions, opts)
|
110
|
+
return versions if opts.level == :all
|
111
|
+
|
112
|
+
n = { major: 0, minor: 1, patch: 2 }[opts.level]
|
113
|
+
versions.group_by { |v| v.segments[0..n] }.map { |_, vs| vs.max or raise }
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
data/lib/all-gem.rb
ADDED
data/sig/all/gem.rbs
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
module AllGem
|
2
|
+
VERSION: String
|
3
|
+
|
4
|
+
class CLI
|
5
|
+
class Error < StandardError
|
6
|
+
attr_reader status: Integer
|
7
|
+
|
8
|
+
def initialize: (String message, ?Integer status) -> void
|
9
|
+
end
|
10
|
+
|
11
|
+
class Options
|
12
|
+
attr_accessor remote: bool
|
13
|
+
attr_accessor since: Gem::Version?
|
14
|
+
attr_accessor level: :all | :major | :minor | :patch
|
15
|
+
end
|
16
|
+
|
17
|
+
attr_reader stdout: IO
|
18
|
+
attr_reader sderr: IO
|
19
|
+
attr_reader stdin: IO
|
20
|
+
attr_reader opts: Options
|
21
|
+
attr_reader op: OptionParser
|
22
|
+
|
23
|
+
@op: OptionParser
|
24
|
+
|
25
|
+
def initialize: (stdout: IO, stderr: IO, stdin: IO) -> void
|
26
|
+
|
27
|
+
def run: (Array[String]) -> void
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def set_optparse: () -> void
|
32
|
+
|
33
|
+
def help: () -> String
|
34
|
+
|
35
|
+
def gemspec_from_command: (String command) -> Gem::Specification
|
36
|
+
|
37
|
+
def versions_of: (Gem::Specification, Options) -> Array[Gem::Version]
|
38
|
+
|
39
|
+
def local_versions: (Gem::Specification) -> Array[Gem::Version]
|
40
|
+
|
41
|
+
def remote_versions: (Gem::Specification) -> Array[Gem::Version]
|
42
|
+
|
43
|
+
def install!: (Gem::Specification, Array[Gem::Version]) -> void
|
44
|
+
|
45
|
+
def filter_by_level: (Array[Gem::Version], Options) -> Array[Gem::Version]
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Gem
|
2
|
+
class Specification < BasicSpecification
|
3
|
+
extend Enumerable[Specification]
|
4
|
+
|
5
|
+
attr_reader name: String
|
6
|
+
attr_reader version: Version
|
7
|
+
|
8
|
+
def self.each: () -> Enumerator[Specification, Array[Specification]]
|
9
|
+
| () { (Specification) -> void } -> Array[Specification]
|
10
|
+
|
11
|
+
def executables: () -> Array[String]
|
12
|
+
end
|
13
|
+
|
14
|
+
class NameTuple
|
15
|
+
attr_reader name: String
|
16
|
+
attr_reader version: Version
|
17
|
+
end
|
18
|
+
|
19
|
+
class Source
|
20
|
+
end
|
21
|
+
|
22
|
+
class Version
|
23
|
+
def segments: () -> Array[Integer]
|
24
|
+
end
|
25
|
+
|
26
|
+
class SpecFetcher
|
27
|
+
def self.fetcher: () -> instance
|
28
|
+
|
29
|
+
type specs_type = :complete | :released | :prerelease | :latest
|
30
|
+
|
31
|
+
def detect: (specs_type) { (NameTuple) -> boolish } -> Array[[NameTuple, Source]]
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: all-gem
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Masataka Pocke Kuwabara
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-01-03 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Run various versions of command provided by gem
|
14
|
+
email:
|
15
|
+
- kuwabara@pocke.me
|
16
|
+
executables:
|
17
|
+
- all-gem
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- Gemfile
|
22
|
+
- README.md
|
23
|
+
- Rakefile
|
24
|
+
- Steepfile
|
25
|
+
- all-gem.gemspec
|
26
|
+
- bin/console
|
27
|
+
- bin/setup
|
28
|
+
- exe/all-gem
|
29
|
+
- lib/all-gem.rb
|
30
|
+
- lib/all-gem/cli.rb
|
31
|
+
- lib/all-gem/version.rb
|
32
|
+
- sig/all/gem.rbs
|
33
|
+
- sig_internal/rubygems.rbs
|
34
|
+
homepage: https://github.com/pocke/all-gem
|
35
|
+
licenses: []
|
36
|
+
metadata:
|
37
|
+
homepage_uri: https://github.com/pocke/all-gem
|
38
|
+
source_code_uri: https://github.com/pocke/all-gem
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.6.0
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubygems_version: 3.4.0.dev
|
55
|
+
signing_key:
|
56
|
+
specification_version: 4
|
57
|
+
summary: Run various versions of command provided by gem
|
58
|
+
test_files: []
|