Class: CSSSprites::CLI

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

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ CLI

Returns a new instance of CLI.



4
5
6
7
# File 'lib/css_sprites/cli.rb', line 4

def initialize(args)
  @args = args
  @options = {}
end

Instance Method Details

#parse!Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/css_sprites/cli.rb', line 9

def parse!
  opts = OptionParser.new(&method(:set_options))
  opts.parse!(@args)
  path = ARGV[0]

  if path
    begin
      output = CSSSprites.generate_sprite(path, @options)
      $stdout.puts "Files saved to #{ output }"
    rescue ArgumentError => error
      $stdout.puts error.message
    end
  else
    $stderr.puts opts.banner
  end
end