Class: Lather::Cli

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

Instance Method Summary collapse

Constructor Details

#initializeCli

Returns a new instance of Cli.



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
# File 'lib/lather/cli.rb', line 7

def initialize
  @command = nil
  @globs = []
  @verbose = false

  @options = OptionParser.new do |o|
    o.banner = "#$0 [-hVv] [-r <cmd>] <globs...>"
    o.separator ""

    o.on "--help", "-h", "-?", "Shows help." do
      exit help!
    end

    o.on "--verbose", "-v", "Talks your ear off." do
      @verbose = true
    end

    o.on "--version", "-V", "Prints #{Lather::VERSION}." do
      puts Lather::VERSION
      exit
    end

    o.on "--rinse [cmd]", "--run", "-r", "Runs when things change." do |cmd|
      @command = cmd
    end

    o.separator ""
  end
end

Instance Method Details

#go!(args) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/lather/cli.rb', line 43

def go! args
  parse! args

  watcher = Lather::Watcher.new @globs do |files|
    if @command
      system @command
    else
      puts "Changed: #{files.join(" ")}"
    end
  end

  verbose "Watching: #{watcher.files.keys.sort.join(" ")}"
  watcher.go!
end

#parse!(args) ⇒ Object



37
38
39
40
41
# File 'lib/lather/cli.rb', line 37

def parse! args
  @options.parse! args
  @globs.concat args
  exit help! if @globs.empty?
end