Class: Md2Cnblog::OptParser

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

Instance Method Summary collapse

Constructor Details

#initializeOptParser

Returns a new instance of OptParser.



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

def initialize()
  @option = OpenStruct.new
end

Instance Method Details

#do(args) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/md2cnblog/cli.rb', line 12

def do(args)
  parser = OptionParser.new do |opts| 
    opts.banner = 'Usage: mdt [type] filename'

    opts.separator ""
    opts.separator "Specific options:"

    opts.on('-t', '--type [BLOGTYPE]', 
           'the blog type to translate') do |t|
      @option.type = t 
    end 

    opts.separator ''
    opts.separator 'Common options:'

    opts.on_tail('-h', '--help', 'show this message') do
      puts opts
      exit
    end
  end # new
  parser.parse!(args)
  @option
end