class Longleaf::CLI

Main commandline interface setup for Longleaf using Thor.

Public Class Methods

add_shared_option(name, group, options = {}) click to toggle source

Register a shared method option in a shared option group

# File lib/longleaf/cli.rb, line 20
def self.add_shared_option(name, group, options = {})
  @shared_groups = {} if @shared_groups.nil?
  @shared_groups[group] = {} if @shared_groups[group].nil?
  @shared_groups[group][name] = options
end
shared_options_group(group_name) click to toggle source

Add all of the shared options in the specified group as method options

# File lib/longleaf/cli.rb, line 27
def self.shared_options_group(group_name)
  @shared_groups[group_name].each do |opt_name, opt|
    option opt_name, opt
  end
end

Public Instance Methods

__print_version() click to toggle source
# File lib/longleaf/cli.rb, line 87
def __print_version
  puts "longleaf version #{Longleaf::VERSION}"
end
deregister() click to toggle source

Deregister event command

# File lib/longleaf/cli.rb, line 166
def deregister
  verify_config_provided(options)
  setup_logger(options)

  app_config_manager = load_application_config(options)
  file_selector = SelectionOptionsParser.create_registered_selector(options, app_config_manager)

  command = DeregisterCommand.new(app_config_manager)
  exit command.execute(file_selector: file_selector, force: options[:force])
end
extend_load_path(load_paths) click to toggle source
# File lib/longleaf/cli.rb, line 278
def extend_load_path(load_paths)
  load_paths = load_paths&.split(/\s*,\s*/)
  load_paths&.each { |path| $LOAD_PATH.unshift(path) }
end
load_application_config(options) click to toggle source
# File lib/longleaf/cli.rb, line 263
def load_application_config(options)
  begin
    app_manager = ApplicationConfigDeserializer.deserialize(options[:config])
  rescue ConfigurationError => err
    logger.failure("Failed to load application configuration due to the following issue(s):\n#{err.message}")
    exit 1
  end
end
preserve() click to toggle source
# File lib/longleaf/cli.rb, line 185
def preserve
  verify_config_provided(options)
  setup_logger(options)

  extend_load_path(options[:load_path])
  app_config_manager = load_application_config(options)
  file_selector = SelectionOptionsParser.create_registered_selector(options, app_config_manager)

  command = PreserveCommand.new(app_config_manager)
  exit command.execute(file_selector: file_selector, force: options[:force])
end
register() click to toggle source

Register event command

# File lib/longleaf/cli.rb, line 143
def register
  verify_config_provided(options)
  setup_logger(options)

  app_config_manager = load_application_config(options)

  file_selector, digest_provider, physical_provider = SelectionOptionsParser
      .parse_registration_selection_options(options, app_config_manager)

  command = RegisterCommand.new(app_config_manager)
  exit command.execute(file_selector: file_selector, force: options[:force], digest_provider: digest_provider,
       physical_provider: physical_provider)
end
reindex() click to toggle source
# File lib/longleaf/cli.rb, line 247
def reindex
  verify_config_provided(options)
  setup_logger(options)
  app_config_manager = load_application_config(options)

  exit Longleaf::ReindexCommand.new(app_config_manager).execute(only_if_stale: options[:if_stale])
end
setup_index() click to toggle source
# File lib/longleaf/cli.rb, line 225
def setup_index
  verify_config_provided(options)
  setup_logger(options)

  app_config_manager = load_application_config(options)

  if app_config_manager.index_manager.using_index?
    app_config_manager.index_manager.setup_index
    logger.success("Setup of index complete")
    exit 0
  else
    logger.failure("No index configured, unable to perform setup.")
    exit 1
  end
end
setup_logger(options) click to toggle source
# File lib/longleaf/cli.rb, line 256
def setup_logger(options)
  initialize_logger(options[:failure_only],
      options[:log_level],
      options[:log_format],
      options[:log_datetime])
end
validate_config() click to toggle source

Application configuration validation command

# File lib/longleaf/cli.rb, line 200
def validate_config
  verify_config_provided(options)
  setup_logger(options)
  extend_load_path(options[:load_path])

  exit Longleaf::ValidateConfigCommand.new(options[:config]).execute
end
validate_metadata() click to toggle source

File metadata validation command

# File lib/longleaf/cli.rb, line 213
def validate_metadata
  verify_config_provided(options)
  setup_logger(options)

  app_config_manager = load_application_config(options)
  file_selector = SelectionOptionsParser.create_registered_selector(options, app_config_manager)

  exit Longleaf::ValidateMetadataCommand.new(app_config_manager).execute(file_selector: file_selector)
end
verify_config_provided(options) click to toggle source
# File lib/longleaf/cli.rb, line 272
def verify_config_provided(options)
  if options[:config].nil? || options[:config].empty?
    raise "No value provided for required options '--config'"
  end
end