Module: FlyIoRails::Utils
- Included in:
- Fly::Generators::AppGenerator, Fly::Generators::ConfigGenerator, Fly::Generators::TerraformGenerator
- Defined in:
- lib/fly.io-rails/utils.rb
Class Method Summary collapse
Instance Method Summary collapse
- #create_app(name: nil, org: 'personal', regions: [], nomad: false, **rest) ⇒ Object
- #tee(cmd) ⇒ Object
Class Method Details
.tee(cmd) ⇒ Object
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 |
# File 'lib/fly.io-rails/utils.rb', line 15 def self.tee cmd data = [] if defined? PTY begin # PTY supports ANSI cursor control and colors PTY.spawn(cmd) do |read, write, pid| begin read.each do |line| print line data << line end rescue Errno::EIO end end rescue PTY::ChildExited end else # no support for ANSI cursor control and colors Open3.popen2e(cmd) do |stdin, out, thread| out.each do |line| print line data << line end end end data.join end |
Instance Method Details
#create_app(name: nil, org: 'personal', regions: [], nomad: false, **rest) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/fly.io-rails/utils.rb', line 45 def create_app(name: nil, org: 'personal', regions: [], nomad: false, **rest) cmd = if name "flyctl apps create #{name.inspect} --org #{org.inspect} --machines" else "flyctl apps create --generate-name --org #{org.inspect} --machines" end cmd.sub! ' --machines', '' if nomad output = tee cmd exit 1 unless output =~ /^New app created: / @app = output.split.last unless regions.empty? @regions = regions.flatten end @app end |
#tee(cmd) ⇒ Object
10 11 12 13 |
# File 'lib/fly.io-rails/utils.rb', line 10 def tee cmd say_status :run, cmd if defined? say_status FlyIoRails::Utils.tee cmd end |