Class: Percy::Cli

Inherits:
Object
  • Object
show all
Includes:
Commander::Methods, Snapshot
Defined in:
lib/percy/cli.rb,
lib/percy/cli/version.rb,
lib/percy/cli/snapshot.rb

Defined Under Namespace

Modules: Snapshot

Constant Summary collapse

DEFAULT_NUM_THREADS =
3
MAX_NUM_THREADS =
10
VERSION =
'1.2.4'

Constants included from Snapshot

Snapshot::DEFAULT_SNAPSHOTS_REGEX, Snapshot::STATIC_RESOURCE_EXTENSIONS

Instance Method Summary collapse

Methods included from Snapshot

#run_snapshot

Instance Method Details

#runObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/percy/cli.rb', line 22

def run
  program :name, 'Percy CLI'
  program :version, Percy::Cli::VERSION
  program :description, 'Command-line interface for Percy (https://percy.io).'
  program :help_formatter, :compact
  default_command :help

  command :snapshot do |c|
    c.syntax = 'snapshot <root_dir>'
    c.description = 'Snapshot a folder of static files.'
    c.option \
      '--baseurl PATH',
      String,
      'The live URL base path. Defaults to "/". Set this if your site is hosted in ' +
      'a subdirectory in production that does not exist locally. If using Jekyll, this ' +
      'should be the same as your "baseurl" config.'
    c.option \
      '--strip_prefix PATH',
      String,
      'Directory path to strip from generated URLs. Defaults to the given root directory.'
    c.option \
      '--repo STRING',
      String,
      'Full GitHub repo slug (owner/repo-name). Defaults to the local git repo origin URL.'
    c.option \
      '--snapshots_regex REGEX',
      String,
      'Regular expression for matching the files to snapshot. Defaults to: "\.(html|htm)$"'
    c.option \
      '--widths CSV',
      String,
      'Comma-separated list of rendering widths for snapshots. Ex: 320,1280"'
    c.option \
      '--snapshot_limit NUM',
      Integer,
      "Max number of snapshots to upload, useful for testing. Default is unlimited."
    c.option \
      '--[no-]enable_javascript',
      "Whether or not to enable JavaScript when rendering all snapshots. Default false."
    c.option \
      '--threads NUM',
      Integer,
      "Number of threads in pools for snapshot and resource uploads. " +
      "Defaults to #{DEFAULT_NUM_THREADS}, max #{MAX_NUM_THREADS}."

    c.action do |args, options|
      options.default threads: DEFAULT_NUM_THREADS
      options.threads = MAX_NUM_THREADS if options.threads > MAX_NUM_THREADS
      options.enable_javascript = options.enable_javascript
      options.widths = (options.widths || '').split(',')

      raise OptionParser::MissingArgument, 'root folder path is required' if args.empty?
      if args.length > 1
        raise OptionParser::MissingArgument, 'only a single root folder path can be given'
      end
      root_dir = args.first

      run_snapshot(root_dir, options.__hash__)
    end
  end

  run!
end

#say(*args) ⇒ Object



14
15
16
# File 'lib/percy/cli.rb', line 14

def say(*args)
  $terminal.say(*args)
end

#say_error(*args) ⇒ Object



18
19
20
# File 'lib/percy/cli.rb', line 18

def say_error(*args)
  STDERR.puts *args
end