Permalink
Browse files

Change name to commandant

  • Loading branch information...
1 parent 04945c5 commit 2d5766a3432db57f24f804201369c3ca928f7021 @reinh committed May 22, 2010
View
@@ -3,7 +3,7 @@
The simplest possible command line subcommand tool. It provides about half of
what you want and none of what you don't. If you don't like it, don't use it.
-Example:
+== Example:
#!/usr/bin/env ruby -rubygems
require 'commander'
View
@@ -4,10 +4,10 @@ require 'rake'
begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
- gem.name = "commander"
+ gem.name = "commandant"
gem.summary = %Q{A simple library for writing commands with subcommands (like git)}
gem.email = "reinh@reinh.com"
- gem.homepage = "http://github.com/reinh/commander"
+ gem.homepage = "http://github.com/reinh/commandant"
gem.authors = ["Rein Henrichs"]
gem.add_development_dependency "rspec", ">= 1.2.9"
gem.add_development_dependency "yard", ">= 0"
@@ -28,6 +28,7 @@ Spec::Rake::SpecTask.new(:rcov) do |spec|
spec.libs << 'lib' << 'spec'
spec.pattern = 'spec/**/*_spec.rb'
spec.rcov = true
+ spec.rcov_opts = ['--exclude /Library,spec/'] # not excluding /Library for some reason"
end
task :spec => :check_dependencies
@@ -38,7 +39,7 @@ begin
require 'yard'
YARD::Rake::YardocTask.new
rescue LoadError
- task :yardoc do
- abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
+ task :yard do
+ abort "YARD is not available. In order to run yard, you must: sudo gem install yard"
end
end
@@ -1,7 +1,7 @@
$LOAD_PATH.unshift(File.dirname(__FILE__))
-require 'commander/command'
+require 'commandant/command'
-module Commander
+module Commandant
COMMANDS = {}
class UnknownCommand < NameError
@@ -30,7 +30,7 @@ def self.clear!
# alias :br => :branch, :co => :checkout
def add_alias(commands)
commands.each do |new, old|
- Commander::COMMANDS[new] = Commander::COMMANDS[old]
+ Commandant::COMMANDS[new] = Commandant::COMMANDS[old]
end
end
module_function :add_alias
@@ -43,18 +43,18 @@ def add_alias(commands)
# @yieldparam [Array] args optional: arguments to the command (typically from ARGV)
#
# @example A Hello World! command
- # Commander.command :hello do
+ # Commandant.command :hello do
# puts "Hello World!"
# end
#
- # Commander.run "hello"
+ # Commandant.run "hello"
#
# @example A command with arguments
- # Commander.command :argprint do |args|
+ # Commandant.command :argprint do |args|
# puts args
# end
#
- # Commander.run "argprint foo bizz bazz"
+ # Commandant.run "argprint foo bizz bazz"
def command(name, description="", &command)
Command.new(name, description, &command)
end
@@ -69,7 +69,7 @@ def command(name, description="", &command)
def run(cmdline=ARGV)
name, *args = cmdline
name, args = :main, [name, *args] if name.nil? || COMMANDS[name.to_sym].nil? && COMMANDS[:main]
- Commander.call name.to_sym, args.compact
+ Commandant.call name.to_sym, args.compact
end
module_function :run
@@ -1,4 +1,4 @@
-module Commander
+module Commandant
class Command
attr_reader :description
@@ -1,8 +1,8 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
-describe Commander::Command do
- before { Commander.clear! }
- subject { Commander::Command }
+describe Commandant::Command do
+ before { Commandant.clear! }
+ subject { Commandant::Command }
describe ".new" do
it "requres a name" do
@@ -21,22 +21,22 @@
it "adds the command to the list of commands by name" do
command = subject.new(:name){ "block" }
- Commander::COMMANDS[:name].should == command
+ Commandant::COMMANDS[:name].should == command
end
describe "when the command already exists" do
- before { Commander::Command.new(:dup) { "I am a duplicate" } }
+ before { Commandant::Command.new(:dup) { "I am a duplicate" } }
it do
lambda {
- Commander.command(:dup) { "I am a duplicate" }
+ Commandant.command(:dup) { "I am a duplicate" }
}.should raise_error(ArgumentError)
end
end
end
describe "#call" do
- subject { Commander::Command.new(:name){ "called" } }
+ subject { Commandant::Command.new(:name){ "called" } }
it "calls the given command" do
subject.call.should == "called"
View
@@ -0,0 +1,83 @@
+require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
+
+describe Commandant do
+ before { Commandant.clear! }
+
+ describe ".call" do
+ it "calls the given command" do
+ Commandant.command(:test) { "test" }
+ Commandant.call(:test).should == "test"
+ end
+
+ it "passes args if given" do
+ Commandant.command(:test) {|args| args }
+
+ Commandant.call(:test, "args").should == "args"
+ end
+
+ describe "when the command is unavailable" do
+ subject { lambda{Commandant.call(:missing)} }
+ it { should raise_error(Commandant::UnknownCommand) }
+ end
+ end
+
+ describe ".clear!" do
+ before { Commandant.command(:main){"main"} }
+
+ it "should empty the command list" do
+ lambda {
+ Commandant.clear!
+ }.should change{Commandant::COMMANDS.empty?}.from(false).to(true)
+ end
+ end
+
+ describe ".add_alias" do
+ it "creates an alias for a given command" do
+ Commandant.command(:hello) { "hello" }
+ Commandant.add_alias :hi => :hello
+
+ Commandant.run(:hi).should == "hello"
+ end
+ end
+
+ describe ".command" do
+ subject { Commandant.command(:test) { "this is a test" } }
+ it "creates a new Command with the given name and command block" do
+ should be_a_kind_of(Commandant::Command)
+ end
+ end
+
+ describe ".run" do
+ before { Commandant.command(:main) {|args| "main called with #{args.inspect}" } }
+
+ it "runs the command specified" do
+ Commandant::COMMANDS[:main].should_receive(:call)
+
+ Commandant.run("main")
+ end
+
+ it "runs the command with arguments" do
+ Commandant::COMMANDS[:main].should_receive(:call).with(["args"])
+
+ Commandant.run(%w{main args})
+ end
+
+ it "defaults to the :main command, if available" do
+ Commandant.run(%w{ some args }).should == 'main called with ["some", "args"]'
+ end
+
+ it "runs the main command if no arguments are passed" do
+ Commandant.run(nil).should == "main called with []"
+ end
+
+ it "raises an errur of no main command is available" do
+ Commandant.clear!
+
+ lambda {
+ Commandant.run(%w{ some args })
+ }.should raise_error(Commandant::UnknownCommand)
+ end
+
+ end
+
+end
View
@@ -1,83 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
-
-describe Commander do
- before { Commander.clear! }
-
- describe ".call" do
- it "calls the given command" do
- Commander.command(:test) { "test" }
- Commander.call(:test).should == "test"
- end
-
- it "passes args if given" do
- Commander.command(:test) {|args| args }
-
- Commander.call(:test, "args").should == "args"
- end
-
- describe "when the command is unavailable" do
- subject { lambda{Commander.call(:missing)} }
- it { should raise_error(Commander::UnknownCommand) }
- end
- end
-
- describe ".clear!" do
- before { Commander.command(:main){"main"} }
-
- it "should empty the command list" do
- lambda {
- Commander.clear!
- }.should change{Commander::COMMANDS.empty?}.from(false).to(true)
- end
- end
-
- describe ".add_alias" do
- it "creates an alias for a given command" do
- Commander.command(:hello) { "hello" }
- Commander.add_alias :hi => :hello
-
- Commander.run(:hi).should == "hello"
- end
- end
-
- describe ".command" do
- subject { Commander.command(:test) { "this is a test" } }
- it "creates a new Command with the given name and command block" do
- should be_a_kind_of(Commander::Command)
- end
- end
-
- describe ".run" do
- before { Commander.command(:main) {|args| "main called with #{args.inspect}" } }
-
- it "runs the command specified" do
- Commander::COMMANDS[:main].should_receive(:call)
-
- Commander.run("main")
- end
-
- it "runs the command with arguments" do
- Commander::COMMANDS[:main].should_receive(:call).with(["args"])
-
- Commander.run(%w{main args})
- end
-
- it "defaults to the :main command, if available" do
- Commander.run(%w{ some args }).should == 'main called with ["some", "args"]'
- end
-
- it "runs the main command if no arguments are passed" do
- Commander.run(nil).should == "main called with []"
- end
-
- it "raises an errur of no main command is available" do
- Commander.clear!
-
- lambda {
- Commander.run(%w{ some args })
- }.should raise_error(Commander::UnknownCommand)
- end
-
- end
-
-end
@@ -1,5 +1,5 @@
-require 'lib/commander'
-include Commander
+require 'lib/commandant'
+include Commandant
command :main do
print "main"
View
@@ -0,0 +1 @@
+--exclude /Library
View
@@ -1,6 +1,6 @@
$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
-require 'commander'
+require 'commandant'
require 'spec'
require 'spec/autorun'

0 comments on commit 2d5766a

Please sign in to comment.