Module: Factorix::CLI::Commands::CommandWrapper

Defined in:
lib/factorix/cli/commands/command_wrapper.rb

Overview

Module that wraps command execution to perform setup and error handling

This module is prepended to Base to ensure configuration loading, log level setup, and consistent error handling happen for every command execution.

Instance Method Summary collapse

Instance Method Details

#call(**options) ⇒ Object

Performs setup before command execution, then calls the command’s implementation Catches exceptions and displays user-friendly error messages

Parameters:

  • options (Hash)

    command options including :config_path and :log_level



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/factorix/cli/commands/command_wrapper.rb', line 17

def call(**options)
  @quiet = options[:quiet]

  load_config!(options[:config_path])
  log_level!(options[:log_level]) if options[:log_level]

  super
rescue Error => e
  # Expected errors (validation failures, missing dependencies, etc.)
  log = Container[:logger]
  log.warn(e.message)
  log.debug(e)
  say "Error: #{e.message}", prefix: :error unless @quiet
  raise # Re-raise for exe/factorix to handle exit code
rescue => e
  # Unexpected errors (bugs, system failures, etc.)
  log = Container[:logger]
  log.error(e)
  say "Unexpected error: #{e.message}", prefix: :error unless @quiet
  raise # Re-raise for exe/factorix to handle exit code
end