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.



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

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



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

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



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
267
# File 'lib/local_development_gateway.rb', line 240

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