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.



248
249
250
251
252
253
# File 'lib/local_development_gateway.rb', line 248

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



244
245
246
# File 'lib/local_development_gateway.rb', line 244

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



255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/local_development_gateway.rb', line 255

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