Class: Docks::CommandLine

Inherits:
Object
  • Object
show all
Defined in:
lib/docks/command_line.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arguments) ⇒ CommandLine

Returns a new instance of CommandLine.



10
11
12
# File 'lib/docks/command_line.rb', line 10

def initialize(arguments)
  @arguments = arguments
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



8
9
10
# File 'lib/docks/command_line.rb', line 8

def arguments
  @arguments
end

Instance Method Details

#initObject



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
# File 'lib/docks/command_line.rb', line 14

def init
  options = {
    config_type: "yaml",
    template_language: "erb",
    script_language: "javascript",
    style_language: "scss"
  }

  OptionParser.new do |opt|
    opt.banner = "Usage: docks init [options]"

    opt.on("--config TYPE", %w(yaml json ruby), "The type of config file to generate (yaml, json, or ruby; default is yaml)") { |type| options[:config_type] = type }
    opt.on("--template LANGUAGE", %w(erb haml), "The language of markup templates to generate (erb or haml; default is erb).") { |language| options[:template_language] = language }
    opt.on("--scripts LANGUAGE", %w(javascript coffeescript), "The scripting language to generate helpers for (javascript or coffeescript; default is javascript).") { |language| options[:script_language] = language }
    opt.on("--styles PREPROCESSOR", %w(scss sass less stylus), "The CSS preprocessor to generate style helpers for (scss, sass, stylus or less; default is scss).") { |language| options[:style_language] = language }
    opt.on("--theme THEME", "The theme to to use as a starting point for your pattern library.") { |theme| options[:theme] = theme }
    opt.on_tail("-h", "--help", "Show this message again.") { puts opt; exit }

    begin
      opt.parse!(arguments)
    rescue => e
    end

    Builder.setup(options)
  end
end

#runObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/docks/command_line.rb', line 41

def run
  return init if arguments[0] == "init"
  config = CONFIG_FILE
  options = {
    clear_cache: false
  }

  OptionParser.new do |opt|
    opt.on("--config FILE", "Path to the configuration file. If no such file is provided, it will default to a file named 'docks_config' in your current directory.") { |config_file| config = config_file }
    opt.on("--clear-cache", "Discard the cache of previous parse results before running.") { |clear_cache| options[:clear_cache] = clear_cache }
    opt.on_tail("-h", "--help", "Show this message again.") { puts opt; exit }
    opt.on_tail("-v", "--version", "Show the version of docks that's running.") { puts "docks #{Docks::VERSION}"; exit }

    begin
      opt.parse!(arguments)
    rescue => e
    end
  end

  Docks.configure_with(config)
  Docks.parse(options)
  Docks.build
end