-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbails
More file actions
executable file
·57 lines (46 loc) · 1.61 KB
/
Copy pathbails
File metadata and controls
executable file
·57 lines (46 loc) · 1.61 KB
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
#!/usr/bin/env ruby
# bails - bin/rails > bundle exec rails > rails, if OSX, ensures that aws login is current
require "colorize"
require "optimist"
require_relative "lib/dbrady_cli"
String.disable_colorization unless $stdout.tty?
class Application
include DbradyCli
def time?
opts[:time]
end
def run
@opts = Optimist.options do
opt :debug, "Print extra debug info", default: false
opt :pretend, "Print commands but do not run them", default: false
opt :verbose, "Run with verbose output (overrides --quiet)", default: false
opt :quiet, "Run with minimal output", default: false
opt :time, "Time command", default: false
opt :tasks, "List tasks", short: :T, default: false
end
opts[:quiet] = !opts[:verbose] if opts[:verbose_given]
puts opts.inspect if opts[:debug]
# Right now, I only want to check aws from my work machine
# If this changes, touch ~/.aws or something?
ensure_aws_sso_login if osx?
command = "bundle exec rails #{arglist}"
command = "time #{command}" if time?
run_command command
end
def passthrough_args
# For now we have to whitelist any args we want to pass through to rails
# TODO: Is there a way take make Optimist leave args it doesn't recognize in ARGV?
{
tasks: "-T"
}.map {|option, arg| arg if opts[option] }.compact
end
def arglist
(passthrough_args + ARGV.map {|arg| arg.match(/\s+/) ? arg.inspect : arg }).join(' ')
end
def ensure_aws_sso_login
run_command("aws sso login") unless run_command("aws-check-sso-login -q")
end
end
if __FILE__ == $0
Application.new.run
end