Class: SiteDiff::Cli

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

Overview

SiteDiff CLI.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.check_unknown_options?(_config) ⇒ Boolean

Thor, by default, does not raise an error for use of unknown options.

Returns:

  • (Boolean)


35
36
37
# File 'lib/sitediff/cli.rb', line 35

def self.check_unknown_options?(_config)
  true
end

.exit_on_failure?Boolean

Thor, by default, exits with 0 no matter what!

Returns:

  • (Boolean)


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(options['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 options['paths'] && options['paths-file']
    SiteDiff.log "Can't specify both --paths-file and --paths.", :error
    exit(-1)
  end

  api = Api.new(options['directory'], config_file)
  api_options =
    clean_keys(
      options,
      :paths,
      :paths_file,
      :ignore_whitespace,
      :export,
      :before,
      :after,
      :cached,
      :verbose,
      :debug,
      :report_format,
      :before_report,
      :after_report
    )
  api_options[:cli_mode] = true
  api.diff(api_options)
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
  api_options =
    clean_keys(
      options,
      :depth,
      :concurrency,
      :interval,
      :include,
      :exclude,
      :preset,
      :crawl
    )
    .merge(
      {
        after_url: urls.pop,
        before_url: urls.pop,
        directory: get_dir(options['directory']),
        curl_opts: get_curl_opts(options)
      }
    )

  Api.init(api_options)
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(options['directory'], config_file)
  api_options = clean_keys(options, :browse, :port)
  api.serve(api_options)
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(options['directory'], config_file)
  api_options = clean_keys(options, :url, :debug)
  api.store(api_options)
end

#versionObject

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 options[:verbose]
    output.push("Website: #{gemspec.homepage}")
    output.push("GitHub: #{gemspec.['source_code_uri']}")
  end
  puts output.join("\n")
end