hiiro 0.1.239 → 0.1.240

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/exe/h +15 -19
  3. data/lib/hiiro/rbenv.rb +92 -0
  4. data/lib/hiiro/version.rb +1 -1
  5. metadata +2 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 49a89f528721bce8e90b9d16c636699b1ea56aa635ac8cc405542e84f8f03a02
4
- data.tar.gz: 576d71d1120411f76dc155cb11c088548009816fca3ea9a3950c750ccd182a81
3
+ metadata.gz: 564e6d6381c8870515ac768d4dc25a60f67160d0f42b814fbc6e0d97da7f0bb8
4
+ data.tar.gz: 56d033c22d775b97ae65fea82523ea2b0e67f47fc0afd59f5cc7cd211d29fffb
5
5
  SHA512:
6
- metadata.gz: 3f16a209a289c0a606dc08010cb48e5a17f5d1df491ac23e1eb31085343856e405d427f6bcc02b645abc158d6ecb392b12939123c1f80ce9120762505fa084c1
7
- data.tar.gz: 50428c767ea91a98a0eea9795978627b1ab54183ca3d20a3f41305968d00b993f520ab0186d8fdd73e60c1920f3bc25e0b7a30ae0fd1b21cf9161c49f1071896
6
+ metadata.gz: faa73ccb87c5e71a2e044a7642806e93a863b47d6003491143b513bb1fbd2b43490c9fed2c4b8ac8397a7669358d3aff9f818baf59afec116e999482872d4d9a
7
+ data.tar.gz: a00aa7f9d62699596f9aa8fb46583ea34e8356712c426789944d455a415d964d967c64f11da1298fb4ff9a01e7ec18c6ffa6df3cb6a4597689720a8055275db0
data/exe/h CHANGED
@@ -4,29 +4,25 @@ require "hiiro"
4
4
  require "fileutils"
5
5
 
6
6
  def update_hiiro(version=nil)
7
- ENV['RBENV_VERSION'] = version.to_s if version
7
+ ver = version || Hiiro::Rbenv.current_version
8
8
  puts
9
- puts "INSTALLING RUBY VERSION #{version}"
10
- env = version ? { 'RBENV_VERSION' => version.to_s } : {}
9
+ puts "INSTALLING RUBY VERSION #{ver}"
11
10
 
12
- gems = Hiiro::Shell.capture_output('rbenv', 'exec', 'gem', 'list', 'hiiro', **env)
13
-
14
- if gems.strip.empty?
15
- system(env, 'rbenv', 'exec', 'gem', 'install', 'hiiro')
16
- else
17
- system(env, 'rbenv', 'exec', 'gem', 'update', 'hiiro')
18
- end
19
-
20
- system(env, 'rbenv', 'exec', 'h', 'setup')
21
- end
22
-
23
- def rbenv_versions
24
- versions = `rbenv versions --bare`.lines(chomp: true)
11
+ Hiiro::Rbenv.install_gem('hiiro', version: ver)
12
+ Hiiro::Rbenv.run('h', 'setup', version: ver)
25
13
  end
26
14
 
27
15
  Hiiro.run(*ARGV, cwd: Dir.pwd, tasks: true) do
28
- add_subcmd(:version) { |*args|
29
- puts Hiiro::VERSION
16
+ add_flag(:all, short: :a, desc: 'Show the version of hiiro for all versions of ruby installed')
17
+
18
+ add_cmd(:version, opts: %i[all]) { |*args|
19
+ if get_flag(:all)
20
+ Hiiro::Rbenv.run_in_all('h', 'version') do |ver, _|
21
+ # version output printed by the subprocess
22
+ end
23
+ else
24
+ puts Hiiro::VERSION
25
+ end
30
26
  }
31
27
 
32
28
  add_subcmd(:ping) { |*args|
@@ -39,7 +35,7 @@ Hiiro.run(*ARGV, cwd: Dir.pwd, tasks: true) do
39
35
  }.parse!(ARGV)
40
36
 
41
37
  if opts.all
42
- rbenv_versions.each do |ver|
38
+ Hiiro::Rbenv.versions.each do |ver|
43
39
  update_hiiro(ver)
44
40
  end
45
41
  else
@@ -0,0 +1,92 @@
1
+ require 'open3'
2
+ require 'shellwords'
3
+
4
+ class Hiiro
5
+ class Rbenv
6
+ class << self
7
+ # --- Version queries ---
8
+
9
+ # All installed rbenv versions (bare list, one per line).
10
+ def versions
11
+ `rbenv versions --bare`.lines(chomp: true)
12
+ end
13
+ alias all_versions versions
14
+
15
+ # The currently active version (respects RBENV_VERSION, .ruby-version, global).
16
+ def current_version
17
+ `rbenv version-name`.strip
18
+ end
19
+
20
+ # The global default version.
21
+ def global_version
22
+ `rbenv global`.strip
23
+ end
24
+
25
+ # The local .ruby-version if one exists in the current directory tree, else nil.
26
+ def local_version
27
+ out = `rbenv local 2>/dev/null`.strip
28
+ out.empty? ? nil : out
29
+ end
30
+
31
+ # True if the given version is installed.
32
+ def has_version?(ver)
33
+ versions.include?(ver.to_s)
34
+ end
35
+
36
+ # Full `ruby --version` string for the given version.
37
+ def ruby_version(version: current_version)
38
+ capture('ruby', '--version', version: version).strip
39
+ end
40
+
41
+ # --- Running commands ---
42
+
43
+ # Run a command through `rbenv exec` in the given version.
44
+ # Returns the exit status (true/false) like Kernel#system.
45
+ def run(*cmd, version: current_version)
46
+ system({ 'RBENV_VERSION' => version.to_s }, 'rbenv', 'exec', *cmd)
47
+ end
48
+
49
+ # Run a command through `rbenv exec` and capture stdout. Returns the output string.
50
+ def capture(*cmd, version: current_version)
51
+ out, = Open3.capture2({ 'RBENV_VERSION' => version.to_s }, 'rbenv', 'exec', *cmd)
52
+ out
53
+ end
54
+
55
+ # Run a command in every installed version. Yields (version, success) if a block given.
56
+ def run_in_all(*cmd)
57
+ versions.each do |ver|
58
+ success = run(*cmd, version: ver)
59
+ yield ver, success if block_given?
60
+ end
61
+ end
62
+
63
+ # --- Gem helpers ---
64
+
65
+ # True if the named gem is installed in the given version.
66
+ def gem_installed?(gem_name, version: current_version)
67
+ !capture('gem', 'list', gem_name, version: version).strip.empty?
68
+ end
69
+
70
+ # Install or update a gem in the given version.
71
+ def install_gem(gem_name, version: current_version)
72
+ if gem_installed?(gem_name, version: version)
73
+ run('gem', 'update', gem_name, version: version)
74
+ else
75
+ run('gem', 'install', gem_name, version: version)
76
+ end
77
+ end
78
+
79
+ # Install or update a gem across all installed versions.
80
+ def install_gem_in_all(gem_name)
81
+ versions.each { |ver| install_gem(gem_name, version: ver) }
82
+ end
83
+
84
+ # --- Path helpers ---
85
+
86
+ # Absolute path to the rbenv shim (or versioned binary) for a command.
87
+ def which(cmd, version: current_version)
88
+ capture('which', cmd, version: version).strip
89
+ end
90
+ end
91
+ end
92
+ end
data/lib/hiiro/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Hiiro
2
- VERSION = "0.1.239"
2
+ VERSION = "0.1.240"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hiiro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.239
4
+ version: 0.1.240
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Toyota
@@ -155,6 +155,7 @@ files:
155
155
  - lib/hiiro/options.rb
156
156
  - lib/hiiro/paths.rb
157
157
  - lib/hiiro/queue.rb
158
+ - lib/hiiro/rbenv.rb
158
159
  - lib/hiiro/runner_tool.rb
159
160
  - lib/hiiro/service_manager.rb
160
161
  - lib/hiiro/shell.rb