Class: Longleaf::CLI

Inherits:
Thor
  • Object
show all
Includes:
Logging
Defined in:
lib/longleaf/cli.rb

Overview

Main commandline interface setup for Longleaf using Thor.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

#initialize_logger, initialize_logger, logger, #logger

Class Method Details

.add_shared_option(name, group, options = {}) ⇒ Object

Register a shared method option in a shared option group



20
21
22
23
24
# 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) ⇒ Object

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



27
28
29
30
31
# 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

Instance Method Details

#__print_versionObject



87
88
89
# File 'lib/longleaf/cli.rb', line 87

def __print_version
  puts "longleaf version #{Longleaf::VERSION}"
end

#deregisterObject

Deregister event command



166
167
168
169
170
171
172
173
174
175
# 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

#preserveObject



185
186
187
188
189
190
191
192
193
194
195
# 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

#registerObject

Register event command



143
144
145
146
147
148
149
150
151
152
153
154
155
# 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

#reindexObject



247
248
249
250
251
252
253
# 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_indexObject



225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# 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

#validate_configObject

Application configuration validation command



200
201
202
203
204
205
206
# 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_metadataObject

File metadata validation command



213
214
215
216
217
218
219
220
221
# File 'lib/longleaf/cli.rb', line 213

def 
  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