Class: DockerRailsProxy::Cli

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

Class Method Summary collapse

Class Method Details

.invoke(arguments) ⇒ Object



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
# File 'lib/docker_rails_proxy/cli.rb', line 4

def invoke(arguments)
  command, *all_arguments         = arguments
  arguments, additional_arguments = split_arguments(all_arguments)

  if command.nil?
    $stderr.puts <<-EOF
    #{"bin/#{APP_NAME} requires 1 argument.".bold}

    #{"Usage: bin/#{APP_NAME} <command> [<arguments>]".bold}
    EOF
    exit 1
  end

  if COMMANDS.include? command
    arguments << '-h' if arguments.empty?
    "DockerRailsProxy::#{command}".constantize.call(
      arguments: arguments, additional_arguments: additional_arguments
    )
  else
    $stderr.puts <<-EOS
    #{'No such command'.yellow}

    #{'COMMANDS'.bold}
    EOS

    COMMANDS.each do |script|
      $stderr.puts <<-EOS
      #{script.parameterize.bold} [<arguments>]
      EOS
    end

    exit 1
  end
end