Class: Metaclean::CLI
- Inherits:
-
Object
- Object
- Metaclean::CLI
- Defined in:
- lib/metaclean/cli.rb
Class Method Summary collapse
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.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/metaclean/cli.rb', line 13 def initialize(argv) @argv = argv.dup @options = { recursive: false, in_place: false, force: false, inspect_only: false, dry_run: false } @paths = [] end |
Class Method Details
.start(argv) ⇒ Object
9 10 11 |
# File 'lib/metaclean/cli.rb', line 9 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 → a required tool (exiftool/mat2/qpdf/ffmpeg) is missing (install hint shown)
130→ user pressed Ctrl-C (matches the standard SIGINT exit code)
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 |
# File 'lib/metaclean/cli.rb', line 31 def run parse! # Refuse to run unless all four external tools are present (see # Metaclean.ensure_tools!). --help/--version already exited inside parse!, # so this only gates an actual inspect/clean. Metaclean.ensure_tools! runner = Runner.new(@options) if @options[:inspect_only] runner.inspect_paths(@paths) else runner.clean_paths(@paths) end rescue ToolsMissing => e warn Display.error('Missing required tools') warn e. exit 2 rescue Error, SystemCallError => e # Errno::* (disk full, permission denied, read-only fs) is a SIBLING of # our Error, not a subclass; naming it here gives filesystem failures a # clean message + exit 1 instead of a raw backtrace. warn Display.error(e.) exit 1 rescue Interrupt # Print a clean message instead of a stack trace. warn "\n#{Display.error('Interrupted.')}" exit 130 end |