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)


15
16
17
# File 'lib/archaeo/cli.rb', line 15

def self.exit_on_failure?
  true
end

Instance Method Details

#after(url, timestamp) ⇒ Object



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

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

#available(url) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/archaeo/cli.rb', line 106

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

#before(url, timestamp) ⇒ Object



74
75
76
77
78
79
# File 'lib/archaeo/cli.rb', line 74

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

#between(url, from, to) ⇒ Object



95
96
97
98
99
100
101
102
# File 'lib/archaeo/cli.rb', line 95

def between(url, from, to)
  fmt = validate_output_format
  handle_errors do
    cdx = CdxApi.new
    snaps = cdx.between(url, from: from, to: to).to_a
    output_formatted(snaps, fmt)
  end
end

#count(url) ⇒ Object



196
197
198
199
200
# File 'lib/archaeo/cli.rb', line 196

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

#download(url) ⇒ Object



166
167
168
169
170
171
172
173
174
# File 'lib/archaeo/cli.rb', line 166

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



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

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

#fetch_assets(url, timestamp) ⇒ Object



147
148
149
150
151
152
153
154
# File 'lib/archaeo/cli.rb', line 147

def fetch_assets(url, timestamp)
  handle_errors do
    bundle = Fetcher.new.fetch_page_with_assets(
      url, timestamp: timestamp
    )
    output_assets(bundle)
  end
end

#known_urls(domain) ⇒ Object



178
179
180
181
182
183
184
# File 'lib/archaeo/cli.rb', line 178

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

#near(url, timestamp) ⇒ Object



46
47
48
49
50
51
# File 'lib/archaeo/cli.rb', line 46

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

#newest(url) ⇒ Object



64
65
66
67
68
69
# File 'lib/archaeo/cli.rb', line 64

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

#num_pages(url) ⇒ Object



188
189
190
191
192
# File 'lib/archaeo/cli.rb', line 188

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

#oldest(url) ⇒ Object



55
56
57
58
59
60
# File 'lib/archaeo/cli.rb', line 55

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

#save(url) ⇒ Object



121
122
123
124
125
126
127
# File 'lib/archaeo/cli.rb', line 121

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



35
36
37
38
39
40
41
# File 'lib/archaeo/cli.rb', line 35

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

#versionObject



20
21
22
# File 'lib/archaeo/cli.rb', line 20

def version
  puts "archaeo #{VERSION}"
end