Class: Apiary::CLI

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

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (CLI) initialize(args)

A new instance of CLI



9
10
11
12
# File 'lib/apiary/cli.rb', line 9

def initialize(args)
  options = parse_options!(args)
  run(args, options)
end

Instance Attribute Details

- (Object) command (readonly)

Returns the value of attribute command



7
8
9
# File 'lib/apiary/cli.rb', line 7

def command
  @command
end

Instance Method Details

- (Object) parse_options!(args)



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/apiary/cli.rb', line 20

def parse_options!(args)
  @command = nil
  options = {}
  options_parser = OptionParser.new do |opts|
    opts.on("--path [PATH]") do |path|
      options[:apib_path] = path
    end

    opts.on("--api_host API_HOST") do |api_host|
      options[:api_host] = api_host
    end

    opts.on("--browser BROWSER") do |browser|
      options[:browser] = browser
    end

    opts.on("--server") do
      options[:server] = true
    end

    opts.on("--port [PORT]") do |port|
      options[:port] = port
    end

    opts.on('-v', '--version') do
      @command = :version
    end

    opts.on( '-h', '--help') do
      @command = :help
    end
  end

  options_parser.parse!
  options

rescue OptionParser::InvalidOption => e
  puts e
  puts Apiary::Command::Help.banner
  exit 1
end

- (Object) run(args, options)



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

def run(args, options)
  command = args.first
  command = @command if @command
  Apiary::Command::Runner.run(command, options)
end