Class: Contained::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/contained/cli.rb,
lib/contained/cli/base.rb,
lib/contained/cli/init.rb,
lib/contained/cli/setup.rb,
lib/contained/cli/deploy.rb

Overview

Examples:


cli = Contained::CLI.new
cli.parse

Defined Under Namespace

Classes: Base, Deploy, Init, Setup

Instance Method Summary collapse

Constructor Details

#initialize(stdin: $stdin, stdout: $stdout, argv: ARGV) ⇒ CLI

Returns a new instance of CLI.

Parameters:

  • input (IO)
  • output (IO)
  • argv (Array<String>) (defaults to: ARGV)

    the arguments (e.g. [‘deploy’, ‘–help’])



14
15
16
17
18
# File 'lib/contained/cli.rb', line 14

def initialize(stdin: $stdin, stdout: $stdout, argv: ARGV)
  @stdin = stdin
  @stdout = stdout
  @argv = argv
end

Instance Method Details

#parseObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/contained/cli.rb', line 20

def parse
  parser.order!(@argv)
  command = @argv.shift
  return if command.nil?

  handler =
    case command
    when "init" then ::Contained::CLI::Init
    when "setup" then ::Contained::CLI::Setup
    when "deploy" then ::Contained::CLI::Deploy
    else raise ::Contained::Error, "unsupported command=#{command.inspect}"
    end

  handler.handle!(stdin: @stdin, stdout: @stdout, argv: @argv)
end