Method: Meem.parse

Defined in:
lib/meem.rb

.parse(arguments) ⇒ Object

Parse options.

arguments - An Array of arguments.

Returns options.



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
68
69
70
71
72
73
74
75
# File 'lib/meem.rb', line 36

def self.parse arguments
  arguments = ["--help"] if arguments.empty?

  options      = OpenStruct.new
  options.meme = arguments.first

  OptionParser.new do |opts|
    opts.program_name = "meem"
    opts.banner = "usage: meem <meme> [options]"
    opts.version = Meem::VERSION

    opts.on "-l", "--list", "List memes" do
      Templates.list.each do |file|
        puts file.basename.to_s[/(.*)\.jpg/, 1]
      end

      exit
    end

    opts.on "-t", "--top TEXT", "Set top text" do |value|
      options.top = value
    end

    opts.on "-b", "--bottom TEXT", "Set bottom text" do |value|
      options.bottom = value
    end
    
    opts.on "-h", "--help", "Show this message" do
      puts opts
      exit
    end

    opts.on "-v", "--version", "Show version" do
      puts Meem::VERSION
      exit
    end
  end.parse! arguments

  options
end