diff --git a/Makefile b/Makefile index 0968fc6..870c697 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,6 @@ +#!/bin/sh +# vi:set filetype=makefile +NULL=0 exec make "CALL=$0" "EXE=`which $0`" -f "`which $0`" -- "$@" D := / PREFIX := /usr/local @@ -5,7 +8,9 @@ BIN_PREFIX := $(PREFIX)/bin all: truckle @echo 'Nothing to do :)' + @echo 'Please run "make install" to install.' install: truckle install -m 0755 truckle $(D)$(BIN_PREFIX)/truckle for c in `./truckle --list-commands`; do ln -fs truckle $(D)$(BIN_PREFIX)/truckle-$${c} ; done + for c in trdo tresume; do ln -fs truckle $(D)$(BIN_PREFIX)/$${c} ; done diff --git a/truckle b/truckle index 0ed09f1..23a979a 100755 --- a/truckle +++ b/truckle @@ -20,7 +20,7 @@ class Commands < Hash end end - attr_accessor :exe, :prefix, :default_cmd + attr_accessor :exe, :prefix, :fallback_cmd def self.arg_unshift arg, args arg = arg.is_a?(Array) ? arg : [arg] @@ -36,11 +36,16 @@ class Commands < Hash r end + def sym_name name + name.to_s.to_sym + end + def on *names, &run + options = names.last.is_a?(Hash) ? names.pop.dup : {} if names.empty? - @default_cmd = run + @fallback_cmd = run else - names.each {|name| self[name.to_s.to_sym] = run } + names.each {|name| self[sym_name name] = run } end end @@ -66,9 +71,9 @@ class Commands < Hash def run *argv c, *argv = self.cmd( argv) - (self[c] || @default_cmd).call c, *argv + (self[c] || @fallback_cmd).call c, *argv rescue CommandError - STDERR.puts $!.message + STDERR.puts $!.message, $!.backtrace exit 1 end alias call run @@ -78,6 +83,11 @@ class Commands < Hash end end +# RunCave +# ======= +# +# Prepare cave-commands. + class RunCave class CommandExpected