Class: Recluse::CLI::Main

Inherits:
Thor
  • Object
show all
Defined in:
lib/recluse/cli/main.rb

Overview

Main commands.

Instance Method Summary collapse

Instance Method Details

#assert(csv_path, *profiles) ⇒ Object



235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/recluse/cli/main.rb', line 235

def assert(csv_path, *profiles)
  if profiles.empty?
    puts 'No profile provided'
    exit(-1)
  end
  begin
    profile_queue = profiles.map { |profile_name| Recluse::Profile.load profile_name }
  rescue ProfileError => e
    puts e
    exit(-1)
  end
  profile = profile_queue[0]
  has_selectors = options['exists'].any? { |selector| !selector.strip.empty? }
  unless has_selectors
    puts 'No selector patterns provided for --exists option'
    exit(-1)
  end
  report = []
  if options[:report_false_only] == options[:report_true_only]
    report = [true, false]
  elsif options[:report_true_only]
    report = [true]
  elsif option[:report_false_only]
    report = [false]
  end
  ending = proc do
    assert_save profile, csv_path, report
    exit
  end

  %w(INT TERM).each do |sig|
    Signal.trap sig, &ending
  end

  (0...profile_queue.length).each do |i|
    profile.results[:assert] = profile_queue[i - 1].results[:assert] unless i.zero?
    profile.test(:assert, selectors: options['exists'])
    profile = profile_queue[i + 1] if i + 1 < profile_queue.length
  end
  %w(INT TERM).each do |sig|
    Signal.trap sig, 'DEFAULT'
  end
  ending.call
end

#find(csv_path, *profiles) ⇒ Object



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/recluse/cli/main.rb', line 197

def find(csv_path, *profiles)
  if profiles.empty?
    puts 'No profile provided'
    exit(-1)
  end
  begin
    profile_queue = profiles.map { |profile_name| Recluse::Profile.load profile_name }
  rescue ProfileError => e
    puts e
    exit(-1)
  end
  profile = profile_queue[0]
  has_globs = options['globs'].any? { |glob| !glob.strip.empty? }
  unless has_globs
    puts 'No glob patterns provided for --globs option'
    exit(-1)
  end
  ending = proc do
    find_save profile, csv_path, group_by: options['group_by'].to_sym
    exit
  end
  %w(INT TERM).each do |sig|
    Signal.trap sig, &ending
  end
  (0...profile_queue.length).each do |i|
    profile.results[:find] = profile_queue[i - 1].results[:find] unless i.zero?
    profile.test(:find, globs: options['globs'])
    profile = profile_queue[i + 1] if i + 1 < profile_queue.length
  end
  %w(INT TERM).each do |sig|
    Signal.trap sig, 'DEFAULT'
  end
  ending.call
end

#status(csv_path, *profiles) ⇒ Object



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/recluse/cli/main.rb', line 150

def status(csv_path, *profiles)
  if profiles.empty?
    puts 'No profile provided'
    exit(-1)
  end
  begin
    profile_queue = profiles.map { |profile_name| Recluse::Profile.load profile_name }
  rescue ProfileError => e
    puts e
    exit(-1)
  end
  profile = profile_queue[0]
  if options['group_by'] == 'page'
    puts 'Page grouping only available with --find.'
    exit(-1)
  end
  begin
    includes = options[:include].map { |code| Recluse::StatusCode.new code }
    if includes.empty?
      puts 'No status codes'
      exit(-1)
    end
    excludes = options[:exclude].map { |code| Recluse::StatusCode.new code }
  rescue StatusCodeError => e
    puts e
    exit(-1)
  end
  ending = proc do
    status_save profile, csv_path, group_by: options['group_by'].to_sym, includes: includes, excludes: excludes
    exit
  end
  %w(INT TERM).each do |sig|
    Signal.trap sig, &ending
  end
  (0...profile_queue.length).each do |i|
    profile.results[:status] = profile_queue[i - 1].results[:status] unless i.zero?
    profile.test :status
    profile = profile_queue[i + 1] if i + 1 < profile_queue.length
  end
  %w(INT TERM).each do |sig|
    Signal.trap sig, 'DEFAULT'
  end
  ending.call
end

#whereObject



280
281
282
283
# File 'lib/recluse/cli/main.rb', line 280

def where
  uconf = UserConfig.new '.recluse'
  puts uconf.directory
end