Class: Imdhemy::Jekyll::Theme::ImageCLI
- Inherits:
-
Object
- Object
- Imdhemy::Jekyll::Theme::ImageCLI
- 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
-
#initialize(argv) ⇒ ImageCLI
constructor
A new instance of ImageCLI.
- #run ⇒ Object
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
#run ⇒ Object
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 = (@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. warn parser.to_s 1 end |