Class: Archaeo::Cli
- Inherits:
-
Thor
- Object
- Thor
- Archaeo::Cli
- 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
Instance Method Summary collapse
- #available(url) ⇒ Object
- #download(url) ⇒ Object
- #fetch(url, timestamp) ⇒ Object
- #known_urls(domain) ⇒ Object
- #near(url, timestamp) ⇒ Object
- #newest(url) ⇒ Object
- #oldest(url) ⇒ Object
- #save(url) ⇒ Object
- #snapshots(url) ⇒ Object
- #version ⇒ Object
Instance Method Details
#available(url) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/archaeo/cli.rb', line 59 def available(url) result = AvailabilityApi.new.near(url) if result.available? puts "Available: #{result.archive_url}" else puts "Not available" exit 1 end end |
#download(url) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/archaeo/cli.rb', line 100 def download(url) downloader = BulkDownloader.new(output_dir: [:output]) downloader.download( url, from: [:from], to: [:to], resume: [:resume], ) do |current, total, snap| warn "[#{current}/#{total}] " \ "#{snap.} #{snap.original_url}" end end |
#fetch(url, timestamp) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/archaeo/cli.rb', line 81 def fetch(url, ) page = Fetcher.new.fetch( url, timestamp: , identity: [:identity] ) if [:output] write_output([:output], page.content) else $stdout.write(page.content) end end |
#known_urls(domain) ⇒ Object
116 117 118 119 120 |
# File 'lib/archaeo/cli.rb', line 116 def known_urls(domain) CdxApi.new.known_urls(domain).each do |u| puts u end end |
#near(url, timestamp) ⇒ Object
41 42 43 44 |
# File 'lib/archaeo/cli.rb', line 41 def near(url, ) snap = CdxApi.new.near(url, timestamp: ) puts snap.archive_url end |
#newest(url) ⇒ Object
53 54 55 56 |
# File 'lib/archaeo/cli.rb', line 53 def newest(url) snap = CdxApi.new.newest(url) puts snap.archive_url end |
#oldest(url) ⇒ Object
47 48 49 50 |
# File 'lib/archaeo/cli.rb', line 47 def oldest(url) snap = CdxApi.new.oldest(url) puts snap.archive_url end |
#save(url) ⇒ Object
70 71 72 73 74 |
# File 'lib/archaeo/cli.rb', line 70 def save(url) result = SaveApi.new.save(url) label = result.cached? ? "Cached" : "Saved" puts "#{label}: #{result.archive_url}" end |
#snapshots(url) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/archaeo/cli.rb', line 28 def snapshots(url) cdx = CdxApi.new opts = () snaps = cdx.snapshots(url, **opts).to_a case [:format] when "json" then output_json(snaps) when "csv" then output_csv(snaps) else output_table(snaps) end end |
#version ⇒ Object
13 14 15 |
# File 'lib/archaeo/cli.rb', line 13 def version puts "archaeo #{VERSION}" end |