Class: Imdhemy::Jekyll::Theme::ImageCLI

Inherits:
Object
  • Object
show all
Defined in:
lib/imdhemy/jekyll/theme/image_cli.rb

Defined Under Namespace

Classes: Result

Constant Summary collapse

SUPPORTED_EXTENSIONS =
%w[.jpg .jpeg .png].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ ImageCLI

Returns a new instance of ImageCLI.



21
22
23
24
25
26
27
# File 'lib/imdhemy/jekyll/theme/image_cli.rb', line 21

def initialize(argv)
  @argv = argv.dup
  @options = {
    recursive: false,
    dry_run: false
  }
end

Class Method Details

.run(argv) ⇒ Object



17
18
19
# File 'lib/imdhemy/jekyll/theme/image_cli.rb', line 17

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

Instance Method Details

#runObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/imdhemy/jekyll/theme/image_cli.rb', line 29

def run
  parser.parse!(@argv)

  if @argv.empty?
    warn parser.to_s
    return 1
  end

  paths = expand_inputs(@argv)
  if paths.empty?
    warn "No supported image files found."
    return 1
  end

  results = paths.map { |path| optimize_path(path) }
  print_results(results)

  results.any? { |result| result.status == :error } ? 1 : 0
rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e
  warn e.message
  warn parser.to_s
  1
end