Class: Archaeo::Cli

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

Overview

Command-line interface powered by Thor.

Constant Summary collapse

CDX_OPTION_MAP =
{
  from: :from,
  to: :to,
  match_type: :match_type,
  filter: :filters,
  collapse: :collapse,
  sort: :sort,
  limit: :limit,
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/archaeo/cli.rb', line 12

def self.exit_on_failure?
  true
end

Instance Method Details

#available(url) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/archaeo/cli.rb', line 70

def available(url)
  handle_errors do
    result = AvailabilityApi.new.near(
      url, timestamp: options[:timestamp]
    )
    if result.available?
      puts "Available: #{result.archive_url}"
    else
      puts "Not available"
      exit 1
    end
  end
end

#download(url) ⇒ Object



116
117
118
119
120
121
122
123
124
# File 'lib/archaeo/cli.rb', line 116

def download(url)
  handle_errors do
    downloader = BulkDownloader.new(
      output_dir: options[:output],
      concurrency: options[:concurrency],
    )
    download_with_progress(downloader, url)
  end
end

#fetch(url, timestamp) ⇒ Object



98
99
100
101
102
103
104
105
106
# File 'lib/archaeo/cli.rb', line 98

def fetch(url, timestamp)
  handle_errors do
    page = Fetcher.new.fetch(
      url, timestamp: timestamp,
           identity: options[:identity]
    )
    output_page(page)
  end
end

#known_urls(domain) ⇒ Object



128
129
130
131
132
133
134
# File 'lib/archaeo/cli.rb', line 128

def known_urls(domain)
  handle_errors do
    CdxApi.new.known_urls(domain).each do |u|
      puts u
    end
  end
end

#near(url, timestamp) ⇒ Object



43
44
45
46
47
48
# File 'lib/archaeo/cli.rb', line 43

def near(url, timestamp)
  handle_errors do
    snap = CdxApi.new.near(url, timestamp: timestamp)
    output_snapshot(snap)
  end
end

#newest(url) ⇒ Object



61
62
63
64
65
66
# File 'lib/archaeo/cli.rb', line 61

def newest(url)
  handle_errors do
    snap = CdxApi.new.newest(url)
    output_snapshot(snap)
  end
end

#num_pages(url) ⇒ Object



138
139
140
141
142
# File 'lib/archaeo/cli.rb', line 138

def num_pages(url)
  handle_errors do
    puts CdxApi.new.num_pages(url)
  end
end

#oldest(url) ⇒ Object



52
53
54
55
56
57
# File 'lib/archaeo/cli.rb', line 52

def oldest(url)
  handle_errors do
    snap = CdxApi.new.oldest(url)
    output_snapshot(snap)
  end
end

#save(url) ⇒ Object



85
86
87
88
89
90
91
# File 'lib/archaeo/cli.rb', line 85

def save(url)
  handle_errors do
    result = SaveApi.new.save(url)
    label = result.cached? ? "Cached" : "Saved"
    puts "#{label}: #{result.archive_url}"
  end
end

#snapshots(url) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/archaeo/cli.rb', line 32

def snapshots(url)
  fmt = validate_output_format
  handle_errors do
    snaps = fetch_snapshots(url)
    output_formatted(snaps, fmt)
  end
end

#versionObject



17
18
19
# File 'lib/archaeo/cli.rb', line 17

def version
  puts "archaeo #{VERSION}"
end