Class: GfmLivePreview::CLI

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

Constant Summary collapse

DEFAULTS =
{
  port: 31337,
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CLI

Returns a new instance of CLI.



11
12
13
# File 'lib/gfm_live_preview/cli.rb', line 11

def initialize(argv)
  @argv = argv
end

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



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

def argv
  @argv
end

Class Method Details

.parse(argv) ⇒ Object



15
16
17
# File 'lib/gfm_live_preview/cli.rb', line 15

def self.parse(argv)
  new(argv).parse
end

Instance Method Details

#parseObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/gfm_live_preview/cli.rb', line 19

def parse
  options = DEFAULTS.dup

  OptionParser.new do |opts|
    opts.banner = "Usage: #{File.basename($PROGRAM_NAME)} [options] FILE"

    opts.on '-p', '--port PORT', 'Specify port other than 31337' do |port|
      options[:port] = port.to_i
    end
  end.parse(argv)

  file = argv.last

  if file.nil?
    @argv = ['-h']
    parse
  end

  [file, options]
end