Class: Metaclean::CLI
- Inherits:
-
Object
- Object
- Metaclean::CLI
- Defined in:
- lib/metaclean/cli.rb
Class Method Summary collapse
-
.start(argv) ⇒ Object
Class-level convenience: ‘Metaclean::CLI.start(ARGV)` reads cleaner than `Metaclean::CLI.new(ARGV).run`.
Instance Method Summary collapse
-
#initialize(argv) ⇒ CLI
constructor
A new instance of CLI.
-
#run ⇒ Object
Top-level dispatcher.
Constructor Details
#initialize(argv) ⇒ CLI
Returns a new instance of CLI.
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 |
# File 'lib/metaclean/cli.rb', line 26 def initialize(argv) # `dup` makes a shallow copy so we can mutate `@argv` without # surprising the caller (ARGV itself stays intact). @argv = argv.dup # All options default to safe/off values. `parse!` flips them # selectively as it sees flags. @options = { recursive: false, in_place: false, no_backup: false, force: false, inspect_only: false, format: :pretty, keep_orientation: false, keep_color_profile: false, dry_run: false, follow_symlinks: false, strict_verify: false, no_mat2: false, no_qpdf: false, no_exiftool: false, exiftool_only: false, types: nil } @paths = [] end |
Class Method Details
.start(argv) ⇒ Object
Class-level convenience: ‘Metaclean::CLI.start(ARGV)` reads cleaner than `Metaclean::CLI.new(ARGV).run`.
22 23 24 |
# File 'lib/metaclean/cli.rb', line 22 def self.start(argv) new(argv).run end |
Instance Method Details
#run ⇒ Object
Top-level dispatcher. Catches our errors and exits with codes that shells/CI can act on:
0 → success
1 → general failure
2 → ExifTool missing (specific install hint shown)
130→ user pressed Ctrl-C (matches the standard SIGINT exit code)
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/metaclean/cli.rb', line 60 def run parse! runner = Runner.new(@options) if @options[:inspect_only] runner.inspect_paths(@paths) else runner.clean_paths(@paths) end rescue ExiftoolMissing => e warn Display.error('ExifTool missing') warn e. exit 2 rescue Error => e warn Display.error(e.) exit 1 rescue Interrupt # Pressing Ctrl-C raises `Interrupt`. Catching it lets us print a # clean message instead of a Ruby stack trace. warn "\n#{Display.error('Interrupted.')}" exit 130 end |