2018-09-20 23:25:39 +00:00
|
|
|
|
|
2018-10-11 07:58:38 +00:00
|
|
|
|
require 'table_print'
|
|
|
|
|
|
2018-09-20 23:25:39 +00:00
|
|
|
|
module Webgalien
|
|
|
|
|
class Cli < Thor
|
|
|
|
|
class_option :'user-agent',
|
|
|
|
|
aliases: '-ua',
|
|
|
|
|
banner: 'USER-AGENT',
|
|
|
|
|
type: :string,
|
|
|
|
|
desc: 'choose user agent (default Mozilla)'
|
2018-10-11 07:58:38 +00:00
|
|
|
|
option :output,
|
|
|
|
|
aliases: '-o',
|
|
|
|
|
banner: 'OUTPUT-FILE',
|
|
|
|
|
type: :string,
|
|
|
|
|
default: 'sitemap.yml',
|
|
|
|
|
desc: 'where sitemap will be produced (default: sitemap.yml)'
|
2018-09-20 23:25:39 +00:00
|
|
|
|
|
|
|
|
|
desc 'sitemap URL FILE', 'crawl site and export sitemap'
|
2018-10-11 07:58:38 +00:00
|
|
|
|
def sitemap url
|
|
|
|
|
Sitemap.start(
|
|
|
|
|
url: url,
|
|
|
|
|
output: options['output']
|
|
|
|
|
)
|
2018-09-20 23:25:39 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
desc 'screenshot FILE', 'take screenshots for each page'
|
2018-10-11 07:58:38 +00:00
|
|
|
|
option :device,
|
|
|
|
|
aliases: '-d',
|
|
|
|
|
banner: 'DEVICE',
|
|
|
|
|
type: :string,
|
|
|
|
|
desc: 'set device from "list-devices" (default "desktop")'
|
2018-09-20 23:25:39 +00:00
|
|
|
|
option :profile,
|
2018-10-11 07:58:38 +00:00
|
|
|
|
aliases: '-r',
|
|
|
|
|
banner: '[portrait|landscape]',
|
2018-09-20 23:25:39 +00:00
|
|
|
|
type: :string,
|
2018-10-11 07:58:38 +00:00
|
|
|
|
desc: 'choose device orientation (default "portrait")'
|
|
|
|
|
option :"output-path",
|
2018-09-20 23:25:39 +00:00
|
|
|
|
aliases: '-o',
|
2018-10-11 07:58:38 +00:00
|
|
|
|
banner: 'OUTPUT-PATH',
|
2018-09-20 23:25:39 +00:00
|
|
|
|
type: :string,
|
2018-10-11 07:58:38 +00:00
|
|
|
|
default: 'cache',
|
|
|
|
|
desc: 'directory where resulting content will be produced'
|
2018-09-20 23:25:39 +00:00
|
|
|
|
|
2018-10-11 07:58:38 +00:00
|
|
|
|
def screenshot sitemap
|
|
|
|
|
if not Devices.exist?(options['device']) then
|
|
|
|
|
STDERR.puts "ERROR: device #{options['device']} does not exist"
|
|
|
|
|
exit 1
|
|
|
|
|
end
|
2018-09-20 23:25:39 +00:00
|
|
|
|
Screenshot.start(
|
2018-10-11 07:58:38 +00:00
|
|
|
|
sitemap: sitemap,
|
|
|
|
|
output_path: options['output-path'],
|
|
|
|
|
device: options['device'],
|
|
|
|
|
orientation: options['orientation']
|
2018-09-20 23:25:39 +00:00
|
|
|
|
)
|
|
|
|
|
end
|
2018-10-11 07:58:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
desc 'list-devices', 'list available profiles'
|
|
|
|
|
def list_devices
|
|
|
|
|
# from https://mediag.com/news/popular-screen-resolutions-designing-for-all/
|
|
|
|
|
Devices.display_list
|
|
|
|
|
end
|
2018-09-20 23:25:39 +00:00
|
|
|
|
end
|
|
|
|
|
end
|