Class: Haute::Cli

Inherits:
Object show all
Defined in:
lib/haute/cli.rb

Class Method Summary collapse

Class Method Details

.runObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
# File 'lib/haute/cli.rb', line 6

def run
  options = {}
  OptionParser.new do |opts|
    opts.banner = "Usage: haute [options]"
    opts.on("-v", "--variables VARIABLES_PATH", "Path to variables") do |v|
      options[:variables] = v
    end
    opts.on("-t", "--typography TYPOGRAPHY_PATH", "Path to typography") do |v|
      options[:typography] = v
    end
    opts.on("-T", "--template TEMPLATE_PATH", "Path to html template") do |v|
      options[:template] = v
    end
    opts.on("-O", "--outfile OUTFILE_PATH", "Path to output style guide to") do |v|
      options[:outfile] = v
    end
    opts.on_tail("-h", "--help", "Show this message") do
      puts opts
      exit(1)
    end

  end.parse!
  if !(path = options.fetch(:variables, nil)).nil?
    begin
      generated = Haute::Generator.generate(Parser.parse_file(path), options[:template])
      if options[:outfile].nil?
        puts generated
      else
        f = File.new(options[:outfile], "w+")
        f.puts(generated)
        f.close
      end
    rescue => e
      puts e
      exit(1)
    end
  else
    puts "The variables flag [-v] is required."
    exit(1)
  end
  exit(0)
end