Module: Extensionator::CLI

Defined in:
lib/extensionator/cli.rb

Class Method Summary collapse

Class Method Details

.fixup_options(in_opts) ⇒ Object



47
48
49
50
51
# File 'lib/extensionator/cli.rb', line 47

def self.fixup_options(in_opts)
  opts = in_opts.clone
  opts[:exclude] = Regexp.new(opts[:exclude]) if opts[:exclude]
  opts
end

.parse_optsObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/extensionator/cli.rb', line 25

def self.parse_opts
  Slop.parse do |o|
    o.string "-d", "--directory", "Directory containing the extension. (Default: .)"
    o.string "-i", "--identity", "Location of the pem file to sign with."
    o.string "-o", "--output", "Location of the output file. (Default: 'output[.zip|.crx|]')"
    o.string "-e", "--exclude", "Regular expression for filenames to exclude. (Default: \.crx$)"
    o.string "-f", "--format", "Type of file to produce, either 'zip', 'dir' or 'crx'. (Default: crx)"
    o.string "--inject-version", "Inject a version number into the manifest file. (Default: none)"
    o.bool "--inject-key", "Inject a key parameter into the manifest file. (Default: no)"
    o.bool "--strip-key", "Remove the key parameter from the manifest file. (Default: no)"
    o.bool "--skip-validation", "Don't try to validate this extension. Currently just checks that the manifest is parsable."
    o.on "-v", "--version", "Extensionator version info." do
      puts Extensionator::VERSION
      exit
    end
    o.on "-h", "--help", "Print this message." do
      puts o
      exit
    end
  end
end

.startObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/extensionator/cli.rb', line 6

def self.start

  opts = parse_opts

  if opts.used_options.empty?
    puts opts
    exit
  end

   method, default = case opts[:format]
    when "zip" then [:zip, "output.zip"]
    when "dir" then [:copy, "output"]
    else [:crx, "output.crx"]
    end

   creator = Creator.new(opts[:directory] || ".", fixup_options(opts))
   creator.send(method, opts[:output] || default)
end