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



21
22
23
24
25
# File 'lib/longleaf/cli.rb', line 21

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



28
29
30
31
32
# File 'lib/longleaf/cli.rb', line 28

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



78
79
80
# File 'lib/longleaf/cli.rb', line 78

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

#deregisterObject

Deregister event command



124
125
126
127
128
129
130
131
132
133
# File 'lib/longleaf/cli.rb', line 124

def deregister
  verify_config_provided(options)
  setup_logger(options)

  app_config_manager = load_application_config(options)
  file_selector = 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



142
143
144
145
146
147
148
149
150
151
152
# File 'lib/longleaf/cli.rb', line 142

def preserve
  verify_config_provided(options)
  setup_logger(options)

  extend_load_path(options[:load_path])
  app_config_manager = load_application_config(options)
  file_selector = 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



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/longleaf/cli.rb', line 93

def register
  verify_config_provided(options)
  setup_logger(options)

  app_config_manager = load_application_config(options)

  file_selector = create_file_selector(options, app_config_manager)
  if options[:checksums]
    checksums = options[:checksums]
    # validate checksum list format, must a comma delimited list of prefix:checksums
    if /^[^:,]+:[^:,]+(,[^:,]+:[^:,]+)*$/.match(checksums)
      # convert checksum list into hash with prefix as key
      checksums = Hash[*checksums.split(/\s*[:,]\s*/)]
    else
      logger.failure("Invalid checksums parameter format, see `longleaf help <command>` for more information")
      exit 1
    end
  end

  command = RegisterCommand.new(app_config_manager)
  exit command.execute(file_selector: file_selector, force: options[:force], checksums: checksums)
end

#reindexObject



203
204
205
206
207
208
209
# File 'lib/longleaf/cli.rb', line 203

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



181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/longleaf/cli.rb', line 181

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



157
158
159
160
161
162
163
# File 'lib/longleaf/cli.rb', line 157

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



169
170
171
172
173
174
175
176
177
# File 'lib/longleaf/cli.rb', line 169

def 
  verify_config_provided(options)
  setup_logger(options)

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

  exit Longleaf::ValidateMetadataCommand.new(app_config_manager).execute(file_selector: file_selector)
end