Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Basic CLI.

  • Loading branch information...
commit 1917950e7998d80ddd4d04fc658f1beb5cf09879 1 parent 1864dcf
@jbarnette authored
View
6 bin/lather 100644 → 100755
@@ -0,0 +1,6 @@
+#!/usr/bin/env ruby -w
+
+require File.expand_path(File.dirname(__FILE__) + "/../lib/lather")
+require "lather/cli"
+
+Lather::Cli.new(STDOUT).go! ARGV
View
1  lib/lather.rb
@@ -3,3 +3,4 @@
$:.include?(File.expand_path(File.dirname(__FILE__)))
require "lather/version"
+require "lather/watcher"
View
62 lib/lather/cli.rb
@@ -0,0 +1,62 @@
+require "optparse"
+
+module Lather
+ class Cli
+ def initialize out
+ @out = out
+ @globs = []
+ @verbose = false
+
+ @options = OptionParser.new do |o|
+ o.banner = "lather [-hVv] [-r <cmd>] <globs...>" # FIXME
+ 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
+
+ def verbose *args
+ @out.puts args.join(" ") if @verbose
+ end
+
+ def go! args
+ @options.parse!
+
+ @globs.concat args
+ exit help! if @globs.empty?
+
+ watcher = Lather::Watcher.new @globs do |file|
+ if @command
+ out.puts "FIXME: #{@command}"
+ else
+ out.puts "Changed: #{file}"
+ end
+ end
+
+ verbose "Watching: #{watcher.files.join(" ")}"
+ watcher.go!
+ end
+
+ def help!
+ @out.puts @options
+ 1 # process exit code
+ end
+ end
+end
View
16 lib/lather/watcher.rb
@@ -0,0 +1,16 @@
+module Lather
+ class Watcher
+ attr_reader :files
+
+ def initialize *globs, &callback
+ raise ArgumentError, "need a callback" unless block_given?
+
+ @callback = callback
+ @files = globs.flatten.collect { |g| Dir[g] }.flatten
+ end
+
+ def go!
+ puts "FIXME: go!"
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.