xgem 0.0.1 → 0.0.2

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 (3) hide show
  1. data/bin/xgem +40 -5
  2. data/bin/xgem-ruby +1 -1
  3. metadata +1 -1
data/bin/xgem CHANGED
@@ -4,6 +4,7 @@ xgem_root = File.expand_path("#{File.expand_path(__FILE__)}/../..")
4
4
 
5
5
  commands = {
6
6
  "refresh" => -> {
7
+ require "rubygems"
7
8
  require "fileutils"
8
9
 
9
10
  puts "Refreshing xgem cache..."
@@ -11,6 +12,7 @@ commands = {
11
12
  current = 0
12
13
  suffixes = Gem.suffixes.map { |s| Regexp.new("#{Regexp.escape s}\\z") }
13
14
  require_map = {}
15
+ executables = {}
14
16
 
15
17
  print "0/#{total}"
16
18
 
@@ -27,35 +29,65 @@ commands = {
27
29
  end
28
30
  end
29
31
  end
32
+ spec.executables.each do |executable|
33
+ if File.file? "#{spec.bin_dir}/#{executable}"
34
+ executables[executable] = "#{spec.bin_dir}/#{executable}"
35
+ end
36
+ end
30
37
  print "\r#{current += 1}/#{total}"
31
38
  end
32
39
 
33
40
  File.write "#{xgem_root}/data/require_paths", Marshal.dump(require_map)
41
+ File.write "#{xgem_root}/data/executables", Marshal.dump(executables)
34
42
  puts "\rReady to rock and roll!"
35
43
  },
36
44
 
37
45
  "install" => -> {
38
46
  print "Installing xgem-ruby executable... "
39
47
 
40
- File.write "#{$0}-ruby", <<-XGEM_RUBY.gsub(/^ /,"")
48
+ # overwrite RubyGem's wrapper with a shell script
49
+ wrapper_script = <<-XGEMRUBY.gsub(/^ /,"")
41
50
  #!/bin/bash
42
51
 
43
52
  xgem_root="#{__FILE__.inspect[1...-1]}/../.."
44
53
 
45
54
  ruby --disable-gems -I "$xgem_root/lib" -r xgem $@
46
- XGEM_RUBY
55
+ XGEMRUBY
56
+ File.write "#{$0}-ruby", wrapper_script
57
+ File.write "#{File.expand_path __FILE__}-ruby", wrapper_script
58
+
59
+ puts "ok!"
60
+
61
+ print "Making 'xgem' use 'xgem-ruby'... "
62
+
63
+ File.write "#{$0}", <<-XGEM.gsub(/^ /,"")
64
+ #!/bin/bash
65
+
66
+ ruby --disable-gems #{File.expand_path(__FILE__).inspect} $@
67
+ XGEM
47
68
 
48
69
  puts "ok!"
49
70
 
50
71
  commands["refresh"].call
72
+ },
73
+
74
+ "do" => ->(executable, *args) {
75
+ executables = Marshal.load File.open("#{xgem_root}/data/executables", "rb") { |f| f.read }
76
+ if executables[executable]
77
+ exec "#{$0}-ruby", executables[executable], *args
78
+ else
79
+ puts "Unknown executable '#{executable}'. Perhaps try running 'xgem refresh'?"
80
+ exit 1
81
+ end
51
82
  }
52
83
  }
53
84
 
54
- if commands[ARGV.first]
55
- commands[ARGV.first].call
85
+ cmd, *cmd_args = ARGV
86
+ if commands[cmd] and commands[cmd].parameters.take_while { |x,_| x == :req }.count <= cmd_args.count
87
+ commands[cmd].call *cmd_args
56
88
  else
57
89
  puts <<-USAGE.gsub(/^ /,"")
58
- Usage: xgem <command>
90
+ Usage: xgem <command> [<args>...]
59
91
 
60
92
  Available commands are:
61
93
 
@@ -67,6 +99,9 @@ else
67
99
  order to use the 'xgem-ruby' command. Note that this will not
68
100
  modify your system in any way that isn't undoable by running
69
101
  'gem uninstall xgem'.
102
+
103
+ do - Runs an executable provided by a gem. For example
104
+ 'xgem do rails server'
70
105
 
71
106
  USAGE
72
107
  end
@@ -1,3 +1,3 @@
1
- #!/usr/bin/env
1
+ #!/usr/bin/env ruby
2
2
 
3
3
  puts "Please run 'xgem install' and try again."
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xgem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: