forked from 18F/guides-style
-
Notifications
You must be signed in to change notification settings - Fork 0
/
go
executable file
·72 lines (58 loc) · 2.04 KB
/
go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#! /usr/bin/env ruby
#
# The preamble down to the check_ruby_version line was generated by version
# 0.1.8 of the go_script gem. This preamble tries to load bundler state
# from Gemfile.lock if present, then the go_script gem for core functionality.
#
# This means the ./go script will run `gem install` or `bundle install` as
# necessary when invoked for the first time, or when dependencies change. It
# also means that commands invoked within the ./go script do not need to be
# prefixed with `bundle exec`.
require 'English'
Dir.chdir File.dirname(__FILE__)
# If a require statement fails, the script calls try_command_and_restart to
# try to install the necessary gems before re-executing itself with the
# original arguments.
def try_command_and_restart(command)
exit $CHILD_STATUS.exitstatus unless system command
# If the RUBYOPT environment variable is set, bundler will presume that it
# has already run. Hence, filtering out RUBYOPT forces bundler to load its
# state during the re-execution.
env = {}.merge(ENV)
env.delete('RUBYOPT')
exec(env, RbConfig.ruby, *[$PROGRAM_NAME].concat(ARGV))
end
begin
require 'bundler/setup' if File.exist? 'Gemfile'
rescue LoadError
try_command_and_restart 'gem install bundler'
rescue SystemExit
try_command_and_restart 'bundle install'
end
begin
require 'go_script'
rescue LoadError
try_command_and_restart 'gem install go_script' unless File.exist? 'Gemfile'
abort "Please add \"gem 'go_script'\" to your Gemfile"
end
extend GoScript
check_ruby_version '2.2.4'
command_group :dev, 'Development commands'
def_command :update_gems, 'Update Ruby gems' do |gems|
update_gems gems
end
def_command :test, 'Execute automated tests' do |args|
exec_cmd "rake test #{args_to_string args}"
end
def_command :lint, 'Run style-checking tools' do |files|
lint_ruby files
end
def_command :build, 'Test and build the gem' do |args|
test
exec_cmd "rake build #{args_to_string args}"
end
def_command :release, 'Test, build, and release a new gem' do
test
exec_cmd 'rake release'
end
execute_command ARGV