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.
36 37 38 |
# File 'lib/sitediff/cli.rb', line 36 def self.(_config) true end |
.exit_on_failure? ⇒ Boolean
Thor, by default, exits with 0 no matter what!
31 32 33 |
# File 'lib/sitediff/cli.rb', line 31 def self.exit_on_failure? true end |
Instance Method Details
#crawl(config_file = nil) ⇒ Object
Crawls the “before” site to determine “paths”.
241 242 243 244 |
# File 'lib/sitediff/cli.rb', line 241 def crawl(config_file = nil) api = Api.new(['directory'], config_file) api.crawl end |
#diff(config_file = nil) ⇒ Object
Computes diffs.
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/sitediff/cli.rb', line 112 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, :remove_html_comments ) [:cli_mode] = true puts api.diff() end |
#init(*urls) ⇒ Object
Initializes a sitediff (yaml) configuration file.
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/sitediff/cli.rb', line 195 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.
154 155 156 157 158 |
# File 'lib/sitediff/cli.rb', line 154 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.
230 231 232 233 234 |
# File 'lib/sitediff/cli.rb', line 230 def store(config_file = nil) api = Api.new(['directory'], config_file) = clean_keys(, :url, :debug) api.store() end |
#version ⇒ Object
Show version information.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/sitediff/cli.rb', line 43 def version filename = '../../sitediff.gemspec' filename = '/sitediff/sitediff.gemspec' if !File.exist?(File.(filename, __dir__)) && File.exist?(File.('/sitediff/sitediff.gemspec', __dir__)) gemspec = Bundler.load_gemspec(File.(filename, __dir__)) 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 |