Class: Simp

Inherits:
Object
  • Object
show all
Defined in:
bin/simp

Class Method Summary collapse

Class Method Details

.parse(args) ⇒ Object

Return a structure describing the options.



16
17
18
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
# File 'bin/simp', line 16

def self.parse(args)
  # The options specified on the command line will be collected in *options*.
  # We set default values here.
  options = OpenStruct.new
  options.tags = []
  options.url = ""
  options.title = ""

  opts = OptionParser.new do |opts|
    opts.banner = "Usage: example.rb [options]"

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

    # Mandatory argument.
    opts.on("-l", "--link URL",
            "The url to save") do |url|
      options.url << url
    end

    # Mandatory argument.
    opts.on("-n", "--name NAME",
            "The url to save") do |title|
      options.title << title
    end

    # List of arguments.
    opts.on("-t", "--tags foo,bar,baz", Array, "Tags") do |tags|
      options.tags = tags
    end

  end

  opts.parse!(args)
  options
end