Class: LocalDevelopmentGateway::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/local_development_gateway.rb

Constant Summary collapse

USAGE =
<<~USAGE
  Usage: local-development-gateway COMMAND [OPTIONS]

  Commands:
    up, ensure  Start or reuse the shared gateway
    status      Show the gateway Compose status
    ready       Check gateway readiness
    logs        Follow gateway logs
    down, stop  Stop the gateway only when unused

  Other commands are passed to Docker Compose using the packaged assets.
USAGE

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv, client:, output:, error:) ⇒ CLI

Returns a new instance of CLI.



232
233
234
235
236
237
# File 'lib/local_development_gateway.rb', line 232

def initialize(argv, client:, output:, error:)
  @argv = argv.dup
  @client = client
  @output = output
  @error = error
end

Class Method Details

.run(argv, client: Client.new, output: $stdout, error: $stderr) ⇒ Object



228
229
230
# File 'lib/local_development_gateway.rb', line 228

def self.run(argv, client: Client.new, output: $stdout, error: $stderr)
  new(argv, client: client, output: output, error: error).run
end

Instance Method Details

#runObject



239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# File 'lib/local_development_gateway.rb', line 239

def run
  command = @argv.shift
  if command.nil? || %w[help --help -h].include?(command)
    return print_usage(0)
  end

  case command
  when "up", "ensure"
    @client.ensure_running(*@argv)
  when "status"
    @output.write(@client.status)
  when "ready"
    return 0 if @client.ready?

    @error.puts "Local Development Gateway is not ready"
    return 1
  when "logs"
    @client.logs(*@argv, follow: true)
  when "down", "stop"
    report_stop(@client.stop_if_unused)
  else
    @output.write(@client.compose(command, *@argv))
  end
  0
rescue Error => error
  @error.puts error.message
  1
end