webgalen/lib/webgalien/cli.rb

65 lines
1.7 KiB
Ruby
Raw Normal View History

2018-09-20 23:25:39 +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)'
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'
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'
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,
aliases: '-r',
banner: '[portrait|landscape]',
2018-09-20 23:25:39 +00:00
type: :string,
desc: 'choose device orientation (default "portrait")'
option :"output-path",
2018-09-20 23:25:39 +00:00
aliases: '-o',
banner: 'OUTPUT-PATH',
2018-09-20 23:25:39 +00:00
type: :string,
default: 'cache',
desc: 'directory where resulting content will be produced'
2018-09-20 23:25:39 +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(
sitemap: sitemap,
output_path: options['output-path'],
device: options['device'],
orientation: options['orientation']
2018-09-20 23:25:39 +00:00
)
end
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