Class: SiteDiff::Cli
- Inherits:
-
Thor
- Object
- Thor
- SiteDiff::Cli
- Defined in:
- lib/sitediff/cli.rb
Overview
SiteDiff CLI.
Class Method Summary collapse
-
.check_unknown_options?(_config) ⇒ Boolean
Thor, by default, does not raise an error for use of unknown options.
-
.exit_on_failure? ⇒ Boolean
Thor, by default, exits with 0 no matter what!.
Instance Method Summary collapse
-
#crawl(config_file = nil) ⇒ Object
Crawls the “before” site to determine “paths”.
-
#diff(config_file = nil) ⇒ Object
Computes diffs.
-
#init(*urls) ⇒ Object
Initializes a sitediff (yaml) configuration file.
-
#serve(config_file = nil) ⇒ Object
Serves SiteDiff report for accessing in the browser.
-
#store(config_file = nil) ⇒ Object
Caches the current version of the site.
-
#version ⇒ Object
Show version information.
Class Method Details
.check_unknown_options?(_config) ⇒ Boolean
Thor, by default, does not raise an error for use of unknown options.
35 36 37 |
# File 'lib/sitediff/cli.rb', line 35 def self.(_config) true end |
.exit_on_failure? ⇒ Boolean
Thor, by default, exits with 0 no matter what!
30 31 32 |
# File 'lib/sitediff/cli.rb', line 30 def self.exit_on_failure? true end |
Instance Method Details
#crawl(config_file = nil) ⇒ Object
Crawls the “before” site to determine “paths”.
229 230 231 232 |
# File 'lib/sitediff/cli.rb', line 229 def crawl(config_file = nil) api = Api.new(['directory'], config_file) api.crawl end |
#diff(config_file = nil) ⇒ Object
Computes diffs.
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/sitediff/cli.rb', line 102 def diff(config_file = nil) # Determine "paths" override based on options. if ['paths'] && ['paths-file'] SiteDiff.log "Can't specify both --paths-file and --paths.", :error exit(-1) end api = Api.new(['directory'], config_file) = clean_keys( , :paths, :paths_file, :ignore_whitespace, :export, :before, :after, :cached, :verbose, :debug, :report_format, :before_report, :after_report ) [:cli_mode] = true api.diff() end |
#init(*urls) ⇒ Object
Initializes a sitediff (yaml) configuration file.
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/sitediff/cli.rb', line 183 def init(*urls) unless (1..2).cover? urls.size SiteDiff.log 'sitediff init requires one or two URLs', :error exit(2) end = clean_keys( , :depth, :concurrency, :interval, :include, :exclude, :preset, :crawl ) .merge( { after_url: urls.pop, before_url: urls.pop, directory: get_dir(['directory']), curl_opts: get_curl_opts() } ) Api.init() end |
#serve(config_file = nil) ⇒ Object
Serves SiteDiff report for accessing in the browser.
142 143 144 145 146 |
# File 'lib/sitediff/cli.rb', line 142 def serve(config_file = nil) api = Api.new(['directory'], config_file) = clean_keys(, :browse, :port) api.serve() end |
#store(config_file = nil) ⇒ Object
Caches the current version of the site.
218 219 220 221 222 |
# File 'lib/sitediff/cli.rb', line 218 def store(config_file = nil) api = Api.new(['directory'], config_file) = clean_keys(, :url, :debug) api.store() end |
#version ⇒ Object
Show version information.
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/sitediff/cli.rb', line 42 def version gemspec = SiteDiff.gemspec output = [] output.push("Sitediff CLI #{gemspec.version}") if [:verbose] output.push("Website: #{gemspec.homepage}") output.push("GitHub: #{gemspec.['source_code_uri']}") end puts output.join("\n") end |