Class: Fabulous::CLI

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ CLI

Returns a new instance of CLI.



242
243
244
245
246
247
# File 'lib/fabulous/cli.rb', line 242

def initialize(*args)
  super
  @pastel = Pastel.new
  @prompt = TTY::Prompt.new
  configure_client
end

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


238
239
240
# File 'lib/fabulous/cli.rb', line 238

def self.exit_on_failure?
  true
end

Instance Method Details

#check(domain_name) ⇒ Object



368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
# File 'lib/fabulous/cli.rb', line 368

def check(domain_name)
  spinner = TTY::Spinner.new("#{@pastel.cyan('')} Checking availability... ", format: :dots)
  spinner.auto_spin

  begin
    available = client.domains.check(domain_name)
    
    if available
      spinner.success(@pastel.green("#{domain_name} is available!"))
    else
      spinner.stop(@pastel.yellow("#{domain_name} is not available"))
    end
  rescue Fabulous::Error => e
    spinner.error(@pastel.red("✗ Error: #{e.message}"))
    exit 1
  end
end

#expiring(days = 30) ⇒ Object



357
358
359
# File 'lib/fabulous/cli.rb', line 357

def expiring(days = 30)
  invoke :list, [], expiring: days.to_i
end

#info(domain_name) ⇒ Object



305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
# File 'lib/fabulous/cli.rb', line 305

def info(domain_name)
  spinner = TTY::Spinner.new("#{@pastel.cyan('')} Fetching domain info... ", format: :dots)
  spinner.auto_spin

  begin
    info = client.domains.info(domain_name)
    
    if info.nil?
      spinner.error(@pastel.red("✗ Domain not found or no information available"))
      exit 1
    end
    
    spinner.success(@pastel.green("✓ Domain found"))

    puts
    puts @pastel.bold.cyan("" * 60)
    puts @pastel.bold.white("  Domain Information: #{domain_name}")
    puts @pastel.bold.cyan("" * 60)
    puts

    display_info_item("Status", info[:status] || "Active", status_color(info[:status]))
    display_info_item("Created", info[:creation_date] || "-")
    display_info_item("Expires", info[:expiry_date] || "-", expiry_color(info[:expiry_date]))
    display_info_item("Auto-Renew", info[:auto_renew].nil? ? "-" : (info[:auto_renew] ? "Enabled" : "Disabled"), 
                     info[:auto_renew] ? :green : nil)
    display_info_item("Domain Lock", info[:locked].nil? ? "-" : (info[:locked] ? "Locked" : "Unlocked"),
                     info[:locked] ? :green : nil)
    display_info_item("WHOIS Privacy", info[:whois_privacy].nil? ? "-" : (info[:whois_privacy] ? "Enabled" : "Disabled"),
                     info[:whois_privacy] ? :green : nil)

    if info[:nameservers] && info[:nameservers].any?
      puts
      puts @pastel.bold.cyan("Nameservers:")
      info[:nameservers].each_with_index do |ns, i|
        puts "  #{@pastel.dim("#{i + 1}.")} #{@pastel.white(ns)}"
      end
    end

    puts
    puts @pastel.cyan("" * 60)
  rescue Fabulous::Error => e
    spinner.error(@pastel.red("✗ Error: #{e.message}"))
    exit 1
  end
end

#listObject



256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'lib/fabulous/cli.rb', line 256

def list
  spinner = TTY::Spinner.new("#{@pastel.cyan('')} Fetching domains... ", format: :dots)
  spinner.auto_spin

  begin
    domains = if options[:page]
                client.domains.list(page: options[:page])
              else
                client.domains.all
              end
    spinner.success(@pastel.green("✓ Found #{domains.length} domains"))

    # Apply filters
    if options[:filter]
      domains = domains.select { |d| d[:name].include?(options[:filter]) }
      puts @pastel.yellow("Filtered to #{domains.length} domains matching '#{options[:filter]}'")
    end

    if options[:expiring]
      today = Date.today
      domains = domains.select do |d|
        next false unless d[:expiry_date]
        begin
          expiry = Date.parse(d[:expiry_date])
          days = (expiry - today).to_i
          days > 0 && days <= options[:expiring]
        rescue ArgumentError
          false
        end
      end
      puts @pastel.yellow("Showing #{domains.length} domains expiring within #{options[:expiring]} days")
    end

    # Sort domains
    domains = sort_domains(domains, options[:sort])

    # Display domains
    if domains.empty?
      puts @pastel.yellow("No domains found matching your criteria")
    else
      display_domains_table(domains, options[:limit], options[:interactive])
    end
  rescue Fabulous::Error => e
    spinner.error(@pastel.red("✗ Error: #{e.message}"))
    exit 1
  end
end

#search(query) ⇒ Object



352
353
354
# File 'lib/fabulous/cli.rb', line 352

def search(query)
  invoke :list, [], filter: query
end

#summaryObject



387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
# File 'lib/fabulous/cli.rb', line 387

def summary
  spinner = TTY::Spinner.new("#{@pastel.cyan('')} Analyzing portfolio... ", format: :dots)
  spinner.auto_spin

  begin
    domains = client.domains.all
    spinner.success(@pastel.green("✓ Analysis complete"))

    puts
    puts @pastel.bold.cyan("" * 60)
    puts @pastel.bold.white("  Portfolio Summary")
    puts @pastel.bold.cyan("" * 60)
    puts

    # Total domains
    puts "#{@pastel.bold('Total Domains:')} #{@pastel.cyan(domains.length.to_s)}"
    puts

    # Group by year
    by_year = domains.group_by do |d|
      Date.parse(d[:expiry_date]).year rescue "Unknown"
    end

    puts @pastel.bold("Domains by Expiry Year:")
    by_year.sort.each do |year, year_domains|
      bar_length = (year_domains.length.to_f / domains.length * 30).round
      bar = "" * bar_length
      puts "  #{year}: #{@pastel.cyan(bar)} #{year_domains.length}"
    end

    # Expiring soon
    today = Date.today
    expiring_30 = domains.count do |d|
      next false unless d[:expiry_date]
      begin
        expiry = Date.parse(d[:expiry_date])
        days = (expiry - today).to_i
        days > 0 && days <= 30
      rescue
        false
      end
    end

    expiring_90 = domains.count do |d|
      next false unless d[:expiry_date]
      begin
        expiry = Date.parse(d[:expiry_date])
        days = (expiry - today).to_i
        days > 0 && days <= 90
      rescue
        false
      end
    end

    puts
    puts @pastel.bold("Expiring Soon:")
    puts "  Next 30 days: #{color_expiry_count(expiring_30)}"
    puts "  Next 90 days: #{color_expiry_count(expiring_90)}"

    puts
    puts @pastel.cyan("" * 60)
  rescue Fabulous::Error => e
    spinner.error(@pastel.red("✗ Error: #{e.message}"))
    exit 1
  end
end

#versionObject



455
456
457
# File 'lib/fabulous/cli.rb', line 455

def version
  puts "Fabulous CLI v#{Fabulous::VERSION}"
end