Class: RubySpriter::CLI

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

Overview

Command-line interface

Constant Summary collapse

PRESETS =
{
  thumbnail: { columns: 3, frame_count: 9, max_width: 240 },
  preview: { columns: 4, frame_count: 16, max_width: 400 },
  detailed: { columns: 10, frame_count: 50, max_width: 320 },
  contact: { columns: 8, frame_count: 64, max_width: 160 }
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.start(args) ⇒ Object



15
16
17
# File 'lib/ruby_spriter/cli.rb', line 15

def self.start(args)
  new.parse_and_run(args)
end

Instance Method Details

#parse_and_run(args) ⇒ Object



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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/ruby_spriter/cli.rb', line 19

def parse_and_run(args)
  options = {}
  options[:fuzzy_select] = false  # Default to --no-fuzzy (global color select)

  # Handle context-sensitive help before validation
  if args.include?('--help') || args.include?('-h')
    handle_context_sensitive_help(args)
  end

  parser = build_option_parser(options)

  parser.parse!(args)

  # Handle special commands that don't need full processing
  if options[:check_dependencies]
    checker = DependencyChecker.new(verbose: true)
    checker.print_report
    exit(checker.all_satisfied? ? 0 : 1)
  end

  # Validate mutually exclusive options
  if options[:extract] && options[:split]
    raise ValidationError, "--extract and --split are mutually exclusive"
  end

  # Validate --add-meta cannot be combined with processing options
  if options[:add_meta] && (options[:scale_percent] || options[:remove_bg] || options[:sharpen])
    raise ValidationError, "--add-meta cannot be combined with processing options (--scale, --remove-bg, --sharpen)"
  end

  # Validate --by-frame flag requirements
  if options[:by_frame]
    unless options[:remove_bg]
      raise ValidationError, "--by-frame requires --remove-bg"
    end

    unless options[:video] || options[:batch]
      raise ValidationError, "--by-frame requires --video or --batch"
    end
  end

  # Validate --cleanup-cells flag requirements
  if options[:cleanup_cells]
    unless options[:remove_bg]
      raise ValidationError, "--cleanup-cells requires --remove-bg flag"
    end

    if options[:by_frame]
      raise ValidationError, "--cleanup-cells cannot be used with --by-frame (redundant)"
    end

    unless options[:video] || options[:batch]
      raise ValidationError, "--cleanup-cells requires --video or --batch mode"
    end

    if options[:cell_cleanup_threshold]
      unless options[:cell_cleanup_threshold].between?(1.0, 50.0)
        raise ValidationError, "--cell-cleanup-threshold must be between 1.0 and 50.0"
      end
    end
  end

  # Run processor
  processor = Processor.new(options)
  processor.run
rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e
  puts "Error: #{e.message}"
  puts "\nUse --help for usage information"
  exit 1
end