Created
April 7, 2020 17:19
-
-
Save zdennis/401cd19cfd1372f0ee192ceb05fbaf75 to your computer and use it in GitHub Desktop.
script/rails-current and script/rails-next dual booting command runners
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "optparse" | |
SCRIPT_NAME = File.basename(__FILE__) | |
ARGS_TO_FORWARD = ARGV.dup | |
ARGV.delete_if { |arg| arg !~ /-h|--help/ } | |
OptionParser.new do |opts| | |
opts.banner = "Usage: #{SCRIPT_NAME} [options]" | |
opts.on("-h", "--help") do | |
puts <<~STR | |
#{SCRIPT_NAME} runs commands through the Rails version in use | |
by the Gemfile. | |
All arguments are forwarded except for -h and --help. | |
Examples for running bundler commands | |
#{SCRIPT_NAME} bundle config | |
#{SCRIPT_NAME} bundle install | |
#{SCRIPT_NAME} bundle update some_gem --conservative | |
Examples for running rails commands | |
#{SCRIPT_NAME} rails console | |
STR | |
end | |
end.parse! | |
ENV['BUNDLE_GEMFILE'] = 'Gemfile' | |
ENV['BUNDLE_CACHE_PATH'] = 'vendor/cache' | |
ENV['BUNDLE_CONFIG'] = '.bundle/config' | |
if Dir.exists?('vendor/bundle') | |
ENV['BUNDLE_PATH'] = 'vendor/bundle' | |
end | |
if ARGS_TO_FORWARD.first == "bundle" | |
command = ARGS_TO_FORWARD.join(' ') | |
else | |
command = "bundle exec #{ARGS_TO_FORWARD.join(' ')}" | |
end | |
exec command |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "optparse" | |
SCRIPT_NAME = File.basename(__FILE__) | |
ARGS_TO_FORWARD = ARGV.dup | |
ARGV.delete_if { |arg| arg !~ /-h|--help/ } | |
OptionParser.new do |opts| | |
opts.banner = "Usage: #{SCRIPT_NAME} [options]" | |
opts.on("-h", "--help") do | |
puts <<~STR | |
#{SCRIPT_NAME} runs commands through the Rails version in use | |
by the Gemfile_next. | |
All arguments are forwarded except for -h and --help. | |
Examples for running bundler commands | |
#{SCRIPT_NAME} bundle config | |
#{SCRIPT_NAME} bundle install | |
#{SCRIPT_NAME} bundle update some_gem --conservative | |
Examples for running rails commands | |
#{SCRIPT_NAME} rails console | |
STR | |
end | |
end.parse! | |
ENV['BUNDLE_GEMFILE'] = 'Gemfile_next' | |
ENV['BUNDLE_CACHE_PATH'] = 'vendor/cache_next' | |
ENV['BUNDLE_CONFIG'] = '.bundle/config_next' | |
if Dir.exists?('vendor/bundle_next') | |
ENV['BUNDLE_PATH'] = 'vendor/bundle_next' | |
end | |
if ARGS_TO_FORWARD.first == "bundle" | |
command = ARGS_TO_FORWARD.join(' ') | |
else | |
command = "bundle exec #{ARGS_TO_FORWARD.join(' ')}" | |
end | |
exec command |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment