Class: Honey::CLI

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ CLI

Returns a new instance of CLI.



8
9
10
11
# File 'lib/honey/cli.rb', line 8

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

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



6
7
8
# File 'lib/honey/cli.rb', line 6

def command
  @command
end

Instance Method Details

#parse_options!(args) ⇒ Object



19
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
61
62
63
64
65
66
67
# File 'lib/honey/cli.rb', line 19

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

    opts.on("--output [PATH]") do |path|
      options[:output]  = path
    end

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

    opts.on("--api-name API_HOST") do |api_name|
      options[:api_name] = api_name
    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 Honey::Command::Help.banner
  exit 1
end

#run(args, options) ⇒ Object



13
14
15
16
17
# File 'lib/honey/cli.rb', line 13

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