Class: Cabriolet::Commands::BaseCommandHandler

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

Overview

Abstract base class for format-specific command handlers

This class defines the interface that all format command handlers must implement. Each format (CAB, CHM, SZDD, KWAJ, HLP, LIT, OAB) should have its own CommandHandler subclass that inherits from this base class.

The base class provides common functionality and enforces a consistent interface across all format handlers, following the Template Method pattern.

Examples:

Creating a format handler

module Cabriolet
  module CAB
    class CommandHandler < CLI::BaseCommandHandler
      def list(file, options = {})
        # Implementation for listing CAB files
      end
    end
  end
end

Instance Method Summary collapse

Constructor Details

#initialize(verbose: false) ⇒ BaseCommandHandler

Initialize the command handler

Parameters:

  • verbose (Boolean) (defaults to: false)

    Enable verbose output



29
30
31
# File 'lib/cabriolet/cli/base_command_handler.rb', line 29

def initialize(verbose: false)
  @verbose = verbose
end

Instance Method Details

#create(output, files, options = {}) ⇒ Object

Create a new archive

Parameters:

  • output (String)

    Output file path

  • files (Array<String>)

    List of input files

  • options (Hash) (defaults to: {})

    Additional options

Raises:

  • (NotImplementedError)

    Subclass must implement



60
61
62
63
# File 'lib/cabriolet/cli/base_command_handler.rb', line 60

def create(output, files, options = {})
  raise NotImplementedError,
        "#{self.class} must implement #create"
end

#extract(file, output_dir, options = {}) ⇒ Object

Extract files from archive

Parameters:

  • file (String)

    Path to the archive file

  • output_dir (String)

    Output directory path

  • options (Hash) (defaults to: {})

    Additional options

Raises:

  • (NotImplementedError)

    Subclass must implement



49
50
51
52
# File 'lib/cabriolet/cli/base_command_handler.rb', line 49

def extract(file, output_dir, options = {})
  raise NotImplementedError,
        "#{self.class} must implement #extract"
end

#info(file, options = {}) ⇒ Object

Display archive information

Parameters:

  • file (String)

    Path to the archive file

  • options (Hash) (defaults to: {})

    Additional options

Raises:

  • (NotImplementedError)

    Subclass must implement



70
71
72
73
# File 'lib/cabriolet/cli/base_command_handler.rb', line 70

def info(file, options = {})
  raise NotImplementedError,
        "#{self.class} must implement #info"
end

#list(file, options = {}) ⇒ Object

List archive contents

Parameters:

  • file (String)

    Path to the archive file

  • options (Hash) (defaults to: {})

    Additional options

Raises:

  • (NotImplementedError)

    Subclass must implement



38
39
40
41
# File 'lib/cabriolet/cli/base_command_handler.rb', line 38

def list(file, options = {})
  raise NotImplementedError,
        "#{self.class} must implement #list"
end

#test(file, options = {}) ⇒ Object

Test archive integrity

Parameters:

  • file (String)

    Path to the archive file

  • options (Hash) (defaults to: {})

    Additional options

Raises:

  • (NotImplementedError)

    Subclass must implement



80
81
82
83
# File 'lib/cabriolet/cli/base_command_handler.rb', line 80

def test(file, options = {})
  raise NotImplementedError,
        "#{self.class} must implement #test"
end