From b967116bdc8ab55092226b52235013526fda7e48 Mon Sep 17 00:00:00 2001 From: Phil Hagelberg Date: Sat, 27 Oct 2007 12:36:18 -0700 Subject: [PATCH] changed CLI interface to be a bit more consistent --- bin/augment | 10 ++++++---- bin/augment-out | 11 ----------- lib/augment.rb | 11 ++++------- lib/frontends/ansi_color_frontend.rb | 2 +- lib/frontends/augment.el | 4 ++-- lib/frontends/frontend.rb | 2 +- lib/frontends/html_frontend.rb | 2 +- spec/ansi_frontend_spec.rb | 4 ++-- spec/emacs-frontend-test.el | 3 +++ spec/html_frontend_spec.rb | 2 +- 10 files changed, 21 insertions(+), 30 deletions(-) delete mode 100755 bin/augment-out diff --git a/bin/augment b/bin/augment index f63a139..9e87c78 100755 --- a/bin/augment +++ b/bin/augment @@ -3,12 +3,14 @@ $LOAD_PATH << File.dirname(__FILE__) + '/../lib' require 'augment' -if ARGV.first == 'background' - Augment.background +if ARGV.first == '--interactive' + Augment.interactive exit 0 elsif ARGV.size != 2 - puts "Usage: augment BACKEND FILE" + puts "Usage: augment BACKEND/FRONTEND FILE" + puts " or: augment --interactive" + puts "Output or store metadata regarding code." exit 1 end -Augment.new(*ARGV) +Augment.new Augment::BACKENDS[ARGV[0]] || Augment::FRONTENDS[ARGV[0]], ARGV[1] diff --git a/bin/augment-out b/bin/augment-out deleted file mode 100755 index b553b2d..0000000 --- a/bin/augment-out +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env ruby -$LOAD_PATH << File.dirname(__FILE__) + '/../lib' - -require 'augment' - -if ARGV.size != 2 - puts "Usage: augment FRONTEND FILE" - exit 1 -end - -Augment.output(*ARGV) diff --git a/lib/augment.rb b/lib/augment.rb index 35ad09c..7905287 100644 --- a/lib/augment.rb +++ b/lib/augment.rb @@ -14,12 +14,13 @@ class Augment BACKENDS = {} FRONTENDS = {} - def initialize(backend_name, file) - BACKENDS[backend_name].run(file) + def initialize(action, file) + raise "No backend or frontend with that name." if action.nil? + action.run(file) end class << self - def background(backend_names = 'test') + def interactive(backend_names = 'test') while true begin filename = STDIN.gets.chomp @@ -31,10 +32,6 @@ class Augment end end - def output(frontend_name, file) - FRONTENDS[frontend_name].show(file) - end - def augment_path(original) "#{File.dirname(File.expand_path(original))}/.augment/#{File.basename(original)}" end diff --git a/lib/frontends/ansi_color_frontend.rb b/lib/frontends/ansi_color_frontend.rb index 84c9a82..4bffedc 100644 --- a/lib/frontends/ansi_color_frontend.rb +++ b/lib/frontends/ansi_color_frontend.rb @@ -25,7 +25,7 @@ end class AnsiColorFrontend < Frontend class << self - def show(file) + def run(file) puts super(file) end diff --git a/lib/frontends/augment.el b/lib/frontends/augment.el index 7470e88..802b295 100644 --- a/lib/frontends/augment.el +++ b/lib/frontends/augment.el @@ -107,8 +107,8 @@ (defun augment-start-process () (unless (get-process "augment") ;; only one should be running at a time (set-process-filter - (start-process "augment" "*augment-out*" ;; FIXME: don't hardcode path - "/home/phil/projects/augment/bin/augment" "background") + (start-process "augment" "*augment-out*" + "augment" "--interactive") 'augment-filter))) (defun augment-filter (process output) diff --git a/lib/frontends/frontend.rb b/lib/frontends/frontend.rb index 5927ad5..9131390 100644 --- a/lib/frontends/frontend.rb +++ b/lib/frontends/frontend.rb @@ -1,6 +1,6 @@ class Frontend class << self - def show(file) + def run(file) # TODO: deal with overlapping color ranges Layer.read(file).inject(File.read(file)) { |text, layer| process_layer(text, layer) } end diff --git a/lib/frontends/html_frontend.rb b/lib/frontends/html_frontend.rb index 0e9d9ac..8852d9c 100644 --- a/lib/frontends/html_frontend.rb +++ b/lib/frontends/html_frontend.rb @@ -10,7 +10,7 @@ end class HtmlFrontend < Frontend class << self - def show(file) + def run(file) puts " #{file} - Augment diff --git a/spec/ansi_frontend_spec.rb b/spec/ansi_frontend_spec.rb index 1cee287..e89cc0d 100644 --- a/spec/ansi_frontend_spec.rb +++ b/spec/ansi_frontend_spec.rb @@ -13,13 +13,13 @@ describe Frontend, " when outputting ANSI color" do end it "should color red as red" do - output = `../../../bin/augment-out ansi #{PROJECT_ROOT}/lib/drink.rb` + output = `../../../bin/augment ansi #{PROJECT_ROOT}/lib/drink.rb` output.to_s.should include("#{'white'.colorize('white')}") output.to_s.should include("#{'red'.colorize('red')}") end it "should color the test_drink" do - output = `../../../bin/augment-out ansi #{PROJECT_ROOT}/test/test_drink.rb` + output = `../../../bin/augment ansi #{PROJECT_ROOT}/test/test_drink.rb` output.to_s.should match(/\e\[#{String::COLOR_LOOKUP['red']}m *assert/) output.to_s.should match(/\e\[#{String::COLOR_LOOKUP['yellow']}m *junk/) end diff --git a/spec/emacs-frontend-test.el b/spec/emacs-frontend-test.el index 37692dc..36c292f 100644 --- a/spec/emacs-frontend-test.el +++ b/spec/emacs-frontend-test.el @@ -14,6 +14,9 @@ (require 'augment) (require 'flymake) +;; in case it hasn't been properly installed +(setenv "PATH" (concat (getenv "PATH") ":" (expand-file-name "../bin"))) + (elunit-clear-suites) (defsuite augment-suite nil) diff --git a/spec/html_frontend_spec.rb b/spec/html_frontend_spec.rb index 032a1a1..46e9bcc 100644 --- a/spec/html_frontend_spec.rb +++ b/spec/html_frontend_spec.rb @@ -10,7 +10,7 @@ describe Frontend, " when outputting HTML" do end it "should create styled spans around colors" do - output = `../../../bin/augment-out html #{PROJECT_ROOT}/lib/drink.rb` + output = `../../../bin/augment html #{PROJECT_ROOT}/lib/drink.rb` output.to_s.should include("white") end end -- 2.11.4.GIT