gestopft 0.0.4 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +18 -0
- data/Gemfile +3 -0
- data/README.rdoc +10 -10
- data/Rakefile +6 -0
- data/gestopft.gemspec +18 -0
- data/lib/gestopft.rb +7 -10
- data/lib/gestopft/app.rb +82 -82
- data/lib/gestopft/core_ext.rb +1 -1
- data/lib/gestopft/core_ext/array.rb +3 -3
- data/lib/gestopft/core_ext/string.rb +6 -6
- data/lib/gestopft/core_ext/symbol.rb +3 -3
- data/lib/gestopft/option.rb +16 -16
- data/lib/gestopft/version.rb +3 -0
- data/spec/gestopft/option_spec.rb +53 -59
- data/spec/gestopft_spec.rb +73 -88
- metadata +62 -37
    
        data/.gitignore
    ADDED
    
    
    
        data/Gemfile
    ADDED
    
    
    
        data/README.rdoc
    CHANGED
    
    | @@ -9,25 +9,25 @@ Framework for CLI Application (like {App::CLI}[http://search.cpan.org/dist/App-C | |
| 9 9 |  | 
| 10 10 | 
             
            === Archive
         | 
| 11 11 |  | 
| 12 | 
            -
             | 
| 12 | 
            +
              rake install
         | 
| 13 13 |  | 
| 14 14 | 
             
            === Gem
         | 
| 15 15 |  | 
| 16 | 
            -
             | 
| 16 | 
            +
              gem install gestopft
         | 
| 17 17 |  | 
| 18 18 |  | 
| 19 19 | 
             
            == Synopsis
         | 
| 20 20 |  | 
| 21 | 
            -
             | 
| 21 | 
            +
              require "gestopft"
         | 
| 22 22 |  | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 23 | 
            +
              class Echo < Gestopft::App
         | 
| 24 | 
            +
                option :verbose, "print debug messages."
         | 
| 25 25 |  | 
| 26 | 
            -
             | 
| 27 | 
            -
             | 
| 28 | 
            -
             | 
| 29 | 
            -
             | 
| 30 | 
            -
             | 
| 26 | 
            +
                def echo(message)
         | 
| 27 | 
            +
                  puts "Echo#echo is invoked." if @options[:verbose]
         | 
| 28 | 
            +
                  puts message
         | 
| 29 | 
            +
                end
         | 
| 30 | 
            +
              end
         | 
| 31 31 |  | 
| 32 32 |  | 
| 33 33 | 
             
            == Copyright
         | 
    
        data/Rakefile
    ADDED
    
    
    
        data/gestopft.gemspec
    ADDED
    
    | @@ -0,0 +1,18 @@ | |
| 1 | 
            +
            require File.expand_path('../lib/gestopft/version', __FILE__)
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Gem::Specification.new do |g|
         | 
| 4 | 
            +
              g.name = "gestopft"
         | 
| 5 | 
            +
              g.version = Gestopft::VERSION
         | 
| 6 | 
            +
              g.summary = "Framework for CLI Application"
         | 
| 7 | 
            +
              g.executables = `git ls-files -- bin/*`.split("\n").map {|f| File.basename(f) }
         | 
| 8 | 
            +
              g.files = `git ls-files`.split("\n")
         | 
| 9 | 
            +
              g.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
         | 
| 10 | 
            +
              g.authors = ["aereal"]
         | 
| 11 | 
            +
              g.email = ["aereal@kerare.org"]
         | 
| 12 | 
            +
              g.homepage = "https://github.com/aereal/gestopft"
         | 
| 13 | 
            +
              g.require_path = ["lib"]
         | 
| 14 | 
            +
              g.platform = Gem::Platform::RUBY
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              g.add_development_dependency 'rspec', ['~> 2.8.0']
         | 
| 17 | 
            +
              g.add_development_dependency 'rake', ['~> 0.9.2']
         | 
| 18 | 
            +
            end
         | 
    
        data/lib/gestopft.rb
    CHANGED
    
    | @@ -1,16 +1,13 @@ | |
| 1 | 
            -
             | 
| 2 | 
            -
             | 
| 1 | 
            +
            require "gestopft/version"
         | 
| 3 2 | 
             
            require "gestopft/core_ext"
         | 
| 4 3 |  | 
| 5 4 | 
             
            module Gestopft
         | 
| 6 | 
            -
             | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
            		class NotSatisfiedRequirements < Error; end
         | 
| 11 | 
            -
            	end
         | 
| 5 | 
            +
              module Constants
         | 
| 6 | 
            +
                class Error < ::StandardError; end
         | 
| 7 | 
            +
                class NotSatisfiedRequirements < Error; end
         | 
| 8 | 
            +
              end
         | 
| 12 9 |  | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 10 | 
            +
              autoload :App,    'gestopft/app'
         | 
| 11 | 
            +
              autoload :Option, 'gestopft/option'
         | 
| 15 12 | 
             
            end
         | 
| 16 13 |  | 
    
        data/lib/gestopft/app.rb
    CHANGED
    
    | @@ -1,102 +1,102 @@ | |
| 1 1 | 
             
            # encoding: utf-8
         | 
| 2 2 |  | 
| 3 3 | 
             
            class Gestopft::App
         | 
| 4 | 
            -
             | 
| 4 | 
            +
              include Gestopft::Constants
         | 
| 5 5 |  | 
| 6 | 
            -
             | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 6 | 
            +
              def self.expectation
         | 
| 7 | 
            +
                @expectation ||= []
         | 
| 8 | 
            +
              end
         | 
| 9 9 |  | 
| 10 | 
            -
             | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 10 | 
            +
              def self.option(name, *args)
         | 
| 11 | 
            +
                desc = args.find {|arg| arg.is_a? String }
         | 
| 12 | 
            +
                params = args.find {|arg| arg.is_a? Array }
         | 
| 13 | 
            +
                expectation << Gestopft::Option.new(name, {
         | 
| 14 | 
            +
                  :desc => desc,
         | 
| 15 | 
            +
                  :params => params
         | 
| 16 | 
            +
                })
         | 
| 17 | 
            +
              end
         | 
| 18 18 |  | 
| 19 | 
            -
             | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 19 | 
            +
              def self.run(argv=ARGV)
         | 
| 20 | 
            +
                (app = new(argv)).parse_arg.dispatch
         | 
| 21 | 
            +
                app
         | 
| 22 | 
            +
              end
         | 
| 23 23 |  | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 24 | 
            +
              def self.commands
         | 
| 25 | 
            +
                public_instance_methods - Gestopft::App.public_instance_methods
         | 
| 26 | 
            +
              end
         | 
| 27 27 |  | 
| 28 | 
            -
             | 
| 28 | 
            +
              attr_reader :options
         | 
| 29 29 |  | 
| 30 | 
            -
             | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 33 | 
            -
             | 
| 34 | 
            -
             | 
| 35 | 
            -
             | 
| 30 | 
            +
              def initialize(argv)
         | 
| 31 | 
            +
                @argv = argv.option_args
         | 
| 32 | 
            +
                @expectation = self.class.expectation
         | 
| 33 | 
            +
                @options = {}
         | 
| 34 | 
            +
                @commands = self.class.commands.map {|cmd| method(cmd) }
         | 
| 35 | 
            +
              end
         | 
| 36 36 |  | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 41 | 
            -
             | 
| 42 | 
            -
             | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 45 | 
            -
             | 
| 46 | 
            -
             | 
| 47 | 
            -
             | 
| 48 | 
            -
             | 
| 49 | 
            -
             | 
| 50 | 
            -
             | 
| 51 | 
            -
             | 
| 52 | 
            -
             | 
| 53 | 
            -
             | 
| 54 | 
            -
             | 
| 55 | 
            -
             | 
| 37 | 
            +
              def parse_arg
         | 
| 38 | 
            +
                @expectation.each do |opt|
         | 
| 39 | 
            +
                  if opt.require_args?
         | 
| 40 | 
            +
                    if (
         | 
| 41 | 
            +
                      pos = @argv.find_index(opt.option_name) and
         | 
| 42 | 
            +
                      params = @argv[pos + 1, opt.arity] and
         | 
| 43 | 
            +
                      params.none? {|param| param.option? } and
         | 
| 44 | 
            +
                      params.size == opt.arity
         | 
| 45 | 
            +
                    )
         | 
| 46 | 
            +
                      @options[opt.name] = params
         | 
| 47 | 
            +
                    else
         | 
| 48 | 
            +
                      raise NotSatisfiedRequirements
         | 
| 49 | 
            +
                    end
         | 
| 50 | 
            +
                  else
         | 
| 51 | 
            +
                    @options[opt.name] = opt.option_name
         | 
| 52 | 
            +
                  end
         | 
| 53 | 
            +
                end
         | 
| 54 | 
            +
                self
         | 
| 55 | 
            +
              end
         | 
| 56 56 |  | 
| 57 | 
            -
             | 
| 58 | 
            -
             | 
| 59 | 
            -
             | 
| 60 | 
            -
             | 
| 61 | 
            -
             | 
| 62 | 
            -
             | 
| 63 | 
            -
             | 
| 64 | 
            -
             | 
| 65 | 
            -
             | 
| 66 | 
            -
             | 
| 57 | 
            +
              def dispatch
         | 
| 58 | 
            +
                argv = @argv.reject {|arg| arg.option? }
         | 
| 59 | 
            +
                @commands.each do |cmd|
         | 
| 60 | 
            +
                  if pos = argv.find_index(cmd.name.to_s)
         | 
| 61 | 
            +
                    params = argv[pos + 1, cmd.arity.abs]
         | 
| 62 | 
            +
                    return cmd.call(*params)
         | 
| 63 | 
            +
                  end
         | 
| 64 | 
            +
                end
         | 
| 65 | 
            +
                send(:__default__)
         | 
| 66 | 
            +
              end
         | 
| 67 67 |  | 
| 68 | 
            -
             | 
| 69 | 
            -
             | 
| 70 | 
            -
             | 
| 68 | 
            +
              def help_message
         | 
| 69 | 
            +
                msg = []
         | 
| 70 | 
            +
                msg << <<-BANNER.strip
         | 
| 71 71 | 
             
            Usage:
         | 
| 72 | 
            -
             | 
| 73 | 
            -
             | 
| 72 | 
            +
              $ #{File.basename($0)} [options] #{"command [args, ...]" unless @commands.empty?}
         | 
| 73 | 
            +
                BANNER
         | 
| 74 74 |  | 
| 75 | 
            -
             | 
| 76 | 
            -
             | 
| 77 | 
            -
             | 
| 78 | 
            -
             | 
| 79 | 
            -
             | 
| 80 | 
            -
             | 
| 81 | 
            -
             | 
| 82 | 
            -
             | 
| 83 | 
            -
             | 
| 84 | 
            -
             | 
| 85 | 
            -
             | 
| 75 | 
            +
                unless @expectation.empty?
         | 
| 76 | 
            +
                  msg << "Options: "
         | 
| 77 | 
            +
                  @expectation.each do |opt|
         | 
| 78 | 
            +
                    line = ["\t", opt.option_name]
         | 
| 79 | 
            +
                    line << opt.params.map {|param|
         | 
| 80 | 
            +
                      param.to_s.upcase
         | 
| 81 | 
            +
                    }.join(' ') unless opt.params.empty?
         | 
| 82 | 
            +
                    line << opt.desc unless opt.desc.empty?
         | 
| 83 | 
            +
                    msg << line.join(" ")
         | 
| 84 | 
            +
                  end
         | 
| 85 | 
            +
                end
         | 
| 86 86 |  | 
| 87 | 
            -
             | 
| 88 | 
            -
             | 
| 87 | 
            +
                unless @commands.empty?
         | 
| 88 | 
            +
                  msg << <<-COMMANDS.strip
         | 
| 89 89 | 
             
            Commands:
         | 
| 90 | 
            -
             | 
| 91 | 
            -
             | 
| 92 | 
            -
             | 
| 90 | 
            +
              #{@commands.map {|cmd| cmd.name }.join(' ')}
         | 
| 91 | 
            +
                  COMMANDS
         | 
| 92 | 
            +
                end
         | 
| 93 93 |  | 
| 94 | 
            -
             | 
| 95 | 
            -
             | 
| 96 | 
            -
             | 
| 94 | 
            +
                msg << ""
         | 
| 95 | 
            +
                msg.join("\n\n")
         | 
| 96 | 
            +
              end
         | 
| 97 97 |  | 
| 98 | 
            -
             | 
| 99 | 
            -
             | 
| 100 | 
            -
             | 
| 98 | 
            +
              def __default__
         | 
| 99 | 
            +
                STDOUT.puts help_message
         | 
| 100 | 
            +
              end
         | 
| 101 101 | 
             
            end
         | 
| 102 102 |  | 
    
        data/lib/gestopft/core_ext.rb
    CHANGED
    
    
| @@ -1,13 +1,13 @@ | |
| 1 1 | 
             
            # encoding: utf-8
         | 
| 2 2 |  | 
| 3 3 | 
             
            module StringExtention
         | 
| 4 | 
            -
             | 
| 5 | 
            -
             | 
| 6 | 
            -
             | 
| 4 | 
            +
              def option?
         | 
| 5 | 
            +
                /^--[-a-zA-Z0-9]+$/ === self
         | 
| 6 | 
            +
              end
         | 
| 7 7 |  | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
             | 
| 8 | 
            +
              def to_option
         | 
| 9 | 
            +
                (slice(0..2) == '--' ? '' : '--') + strip.gsub('_', '-')
         | 
| 10 | 
            +
              end
         | 
| 11 11 | 
             
            end
         | 
| 12 12 |  | 
| 13 13 | 
             
            String.send(:include, StringExtention)
         | 
    
        data/lib/gestopft/option.rb
    CHANGED
    
    | @@ -1,25 +1,25 @@ | |
| 1 1 | 
             
            # encoding: utf-8
         | 
| 2 2 |  | 
| 3 3 | 
             
            class Gestopft::Option
         | 
| 4 | 
            -
             | 
| 5 | 
            -
             | 
| 4 | 
            +
              attr_reader :name, :params, :description
         | 
| 5 | 
            +
              alias_method :desc, :description
         | 
| 6 6 |  | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
             | 
| 11 | 
            -
             | 
| 7 | 
            +
              def initialize(name, args={})
         | 
| 8 | 
            +
                @name = name
         | 
| 9 | 
            +
                @params = args[:params] || []
         | 
| 10 | 
            +
                @description = args[:desc] || args[:description] || ""
         | 
| 11 | 
            +
              end
         | 
| 12 12 |  | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 13 | 
            +
              def option_name
         | 
| 14 | 
            +
                @name.to_option
         | 
| 15 | 
            +
              end
         | 
| 16 16 |  | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 17 | 
            +
              def require_args?
         | 
| 18 | 
            +
                !@params.empty?
         | 
| 19 | 
            +
              end
         | 
| 20 20 |  | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 21 | 
            +
              def arity
         | 
| 22 | 
            +
                @params.size
         | 
| 23 | 
            +
              end
         | 
| 24 24 | 
             
            end
         | 
| 25 25 |  | 
| @@ -6,64 +6,58 @@ require "gestopft" | |
| 6 6 | 
             
            include Gestopft::Constants
         | 
| 7 7 |  | 
| 8 8 | 
             
            describe Gestopft::Option do
         | 
| 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 | 
            -
             | 
| 36 | 
            -
             | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 41 | 
            -
             | 
| 42 | 
            -
             | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 45 | 
            -
             | 
| 46 | 
            -
             | 
| 47 | 
            -
             | 
| 48 | 
            -
             | 
| 49 | 
            -
             | 
| 50 | 
            -
             | 
| 51 | 
            -
             | 
| 52 | 
            -
             | 
| 53 | 
            -
             | 
| 54 | 
            -
             | 
| 55 | 
            -
             | 
| 56 | 
            -
             | 
| 57 | 
            -
             | 
| 58 | 
            -
             | 
| 59 | 
            -
             | 
| 60 | 
            -
             | 
| 61 | 
            -
             | 
| 62 | 
            -
             | 
| 63 | 
            -
            	context "generated automatically" do
         | 
| 64 | 
            -
            		subject do
         | 
| 65 | 
            -
            			Gestopft::Option.new(:m, :alias_for => :my_option)
         | 
| 66 | 
            -
            		end
         | 
| 67 | 
            -
            	end
         | 
| 9 | 
            +
              subject do
         | 
| 10 | 
            +
                Gestopft::Option.new(:my_option, :desc => "my description")
         | 
| 11 | 
            +
              end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              it "#option_name is option string." do
         | 
| 14 | 
            +
                subject.option_name.should == '--my-option'
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              context "when given a description." do
         | 
| 18 | 
            +
                it "#desc[ription] is the description about the option." do
         | 
| 19 | 
            +
                  subject.desc.should == "my description"
         | 
| 20 | 
            +
                  subject.description.should == "my description"
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
              end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
              context "when does not given a description." do
         | 
| 25 | 
            +
                subject do
         | 
| 26 | 
            +
                  Gestopft::Option.new(:my_option)
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                it "#desc[ription] is empty." do
         | 
| 30 | 
            +
                  subject.desc.should be_empty
         | 
| 31 | 
            +
                  subject.description.should be_empty
         | 
| 32 | 
            +
                end
         | 
| 33 | 
            +
              end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
              context "which requires parameters." do
         | 
| 36 | 
            +
                subject do
         | 
| 37 | 
            +
                  Gestopft::Option.new(:delay, :params => %w(minute))
         | 
| 38 | 
            +
                end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                it "#require_args? is true" do
         | 
| 41 | 
            +
                  subject.require_args?.should be_true
         | 
| 42 | 
            +
                end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                it "#arity is the arity of option." do
         | 
| 45 | 
            +
                  subject.arity.should == 1
         | 
| 46 | 
            +
                end
         | 
| 47 | 
            +
              end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
              context "which requires no parameter." do
         | 
| 50 | 
            +
                subject do
         | 
| 51 | 
            +
                  Gestopft::Option.new(:verbose)
         | 
| 52 | 
            +
                end
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                it "#require_args? is false" do
         | 
| 55 | 
            +
                  subject.require_args?.should be_false
         | 
| 56 | 
            +
                end
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                it "#arity is 0." do
         | 
| 59 | 
            +
                  subject.arity.should == 0
         | 
| 60 | 
            +
                end
         | 
| 61 | 
            +
              end
         | 
| 68 62 | 
             
            end
         | 
| 69 63 |  | 
    
        data/spec/gestopft_spec.rb
    CHANGED
    
    | @@ -6,93 +6,78 @@ require "gestopft" | |
| 6 6 | 
             
            include Gestopft::Constants
         | 
| 7 7 |  | 
| 8 8 | 
             
            describe Gestopft::App do
         | 
| 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 | 
            -
             | 
| 36 | 
            -
             | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 41 | 
            -
             | 
| 42 | 
            -
             | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 45 | 
            -
             | 
| 46 | 
            -
             | 
| 47 | 
            -
             | 
| 48 | 
            -
             | 
| 49 | 
            -
             | 
| 50 | 
            -
             | 
| 51 | 
            -
             | 
| 52 | 
            -
             | 
| 53 | 
            -
             | 
| 54 | 
            -
             | 
| 55 | 
            -
             | 
| 56 | 
            -
             | 
| 57 | 
            -
             | 
| 58 | 
            -
             | 
| 59 | 
            -
             | 
| 60 | 
            -
             | 
| 61 | 
            -
             | 
| 62 | 
            -
             | 
| 63 | 
            -
             | 
| 64 | 
            -
             | 
| 65 | 
            -
             | 
| 66 | 
            -
             | 
| 67 | 
            -
             | 
| 68 | 
            -
             | 
| 69 | 
            -
             | 
| 70 | 
            -
             | 
| 71 | 
            -
             | 
| 72 | 
            -
             | 
| 73 | 
            -
             | 
| 74 | 
            -
             | 
| 75 | 
            -
             | 
| 76 | 
            -
             | 
| 77 | 
            -
             | 
| 78 | 
            -
             | 
| 79 | 
            -
             | 
| 80 | 
            -
             | 
| 81 | 
            -
             | 
| 82 | 
            -
             | 
| 83 | 
            -
            	context "when given some options" do
         | 
| 84 | 
            -
            		before do
         | 
| 85 | 
            -
            			subject.module_eval do
         | 
| 86 | 
            -
            				option :verbose
         | 
| 87 | 
            -
            				option :dry_run
         | 
| 88 | 
            -
            			end
         | 
| 89 | 
            -
            		end
         | 
| 90 | 
            -
             | 
| 91 | 
            -
            		it "automatically generate short options" do
         | 
| 92 | 
            -
            			subject.expectation.sort.map {|i|
         | 
| 93 | 
            -
            				i.option_name
         | 
| 94 | 
            -
            			}.should.include(%w(-v -d))
         | 
| 95 | 
            -
            		end
         | 
| 96 | 
            -
            	end
         | 
| 9 | 
            +
              subject do
         | 
| 10 | 
            +
                Class.new(Gestopft::App)
         | 
| 11 | 
            +
              end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              context "given a option which requires no arguments." do
         | 
| 14 | 
            +
                before :all do
         | 
| 15 | 
            +
                  subject.module_eval do
         | 
| 16 | 
            +
                    option :with_no_args
         | 
| 17 | 
            +
                  end
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                it "has a option which given." do
         | 
| 21 | 
            +
                  subject.run(%w(--with-no-args)).options.
         | 
| 22 | 
            +
                    should include(:with_no_args)
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                it "does not have a option which does not given." do
         | 
| 26 | 
            +
                  subject.run(%w(--with-no-args)).options.
         | 
| 27 | 
            +
                    should_not include(:does_not_given)
         | 
| 28 | 
            +
                end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                it "succeeds when given a option which requires no arguments." do
         | 
| 31 | 
            +
                  expect { subject.run(%w(--with-no-args)) }.
         | 
| 32 | 
            +
                    should_not raise_error(Error)
         | 
| 33 | 
            +
                end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                it "succeeds when not given a option which is required." do
         | 
| 36 | 
            +
                  expect { subject.run([]) }.
         | 
| 37 | 
            +
                    should_not raise_error(NotSatisfiedRequirements)
         | 
| 38 | 
            +
                end
         | 
| 39 | 
            +
              end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
              context "a option which require a argument." do
         | 
| 42 | 
            +
                before :all do
         | 
| 43 | 
            +
                  subject.module_eval do
         | 
| 44 | 
            +
                    option :delay, [:minute]
         | 
| 45 | 
            +
                  end
         | 
| 46 | 
            +
                end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                it "has a option which given with taken parameter." do
         | 
| 49 | 
            +
                  subject.run(%w(--delay 5)).options.
         | 
| 50 | 
            +
                    should include(:delay => ['5'])
         | 
| 51 | 
            +
                end
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                it "does not have a option which given without any arguments." do
         | 
| 54 | 
            +
                  expect { subject.run(%w(--delay)) }.
         | 
| 55 | 
            +
                    should raise_error(NotSatisfiedRequirements)
         | 
| 56 | 
            +
                end
         | 
| 57 | 
            +
              end
         | 
| 58 | 
            +
             | 
| 59 | 
            +
              context "when defined sub-commands" do
         | 
| 60 | 
            +
                before do
         | 
| 61 | 
            +
                  subject.module_eval do
         | 
| 62 | 
            +
                    def update
         | 
| 63 | 
            +
                      :update
         | 
| 64 | 
            +
                    end
         | 
| 65 | 
            +
                  end
         | 
| 66 | 
            +
                end
         | 
| 67 | 
            +
             | 
| 68 | 
            +
                it ".commands is a array of available commands." do
         | 
| 69 | 
            +
                  subject.commands.should == [:update]
         | 
| 70 | 
            +
                end
         | 
| 71 | 
            +
             | 
| 72 | 
            +
                it "#dispatch return value which of sub-command's" do
         | 
| 73 | 
            +
                  subject.new(%w(update)).dispatch.should == subject.new([]).update
         | 
| 74 | 
            +
                end
         | 
| 75 | 
            +
              end
         | 
| 76 | 
            +
             | 
| 77 | 
            +
              context "when not defined sub-commands" do
         | 
| 78 | 
            +
                it ".commands is empty array." do
         | 
| 79 | 
            +
                  subject.commands.should be_empty
         | 
| 80 | 
            +
                end
         | 
| 81 | 
            +
              end
         | 
| 97 82 | 
             
            end
         | 
| 98 83 |  | 
    
        metadata
    CHANGED
    
    | @@ -1,67 +1,92 @@ | |
| 1 | 
            -
            --- !ruby/object:Gem::Specification | 
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: gestopft
         | 
| 3 | 
            -
            version: !ruby/object:Gem::Version | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.1.0
         | 
| 4 5 | 
             
              prerelease: 
         | 
| 5 | 
            -
              version: 0.0.4
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 | 
            -
            authors: | 
| 7 | 
            +
            authors:
         | 
| 8 8 | 
             
            - aereal
         | 
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 12 | 
            +
            date: 2012-03-08 00:00:00.000000000 Z
         | 
| 13 | 
            +
            dependencies:
         | 
| 14 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 15 | 
            +
              name: rspec
         | 
| 16 | 
            +
              requirement: &70341397648800 !ruby/object:Gem::Requirement
         | 
| 17 | 
            +
                none: false
         | 
| 18 | 
            +
                requirements:
         | 
| 19 | 
            +
                - - ~>
         | 
| 20 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 21 | 
            +
                    version: 2.8.0
         | 
| 22 | 
            +
              type: :development
         | 
| 23 | 
            +
              prerelease: false
         | 
| 24 | 
            +
              version_requirements: *70341397648800
         | 
| 25 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 26 | 
            +
              name: rake
         | 
| 27 | 
            +
              requirement: &70341397648280 !ruby/object:Gem::Requirement
         | 
| 28 | 
            +
                none: false
         | 
| 29 | 
            +
                requirements:
         | 
| 30 | 
            +
                - - ~>
         | 
| 31 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 32 | 
            +
                    version: 0.9.2
         | 
| 33 | 
            +
              type: :development
         | 
| 34 | 
            +
              prerelease: false
         | 
| 35 | 
            +
              version_requirements: *70341397648280
         | 
| 17 36 | 
             
            description: 
         | 
| 18 | 
            -
            email: | 
| 37 | 
            +
            email:
         | 
| 38 | 
            +
            - aereal@kerare.org
         | 
| 19 39 | 
             
            executables: []
         | 
| 20 | 
            -
             | 
| 21 40 | 
             
            extensions: []
         | 
| 22 | 
            -
             | 
| 23 41 | 
             
            extra_rdoc_files: []
         | 
| 24 | 
            -
             | 
| 25 | 
            -
            files: 
         | 
| 26 | 
            -
            - README.rdoc
         | 
| 42 | 
            +
            files:
         | 
| 27 43 | 
             
            - .autotest
         | 
| 44 | 
            +
            - .gitignore
         | 
| 28 45 | 
             
            - .rspec
         | 
| 46 | 
            +
            - Gemfile
         | 
| 47 | 
            +
            - README.rdoc
         | 
| 48 | 
            +
            - Rakefile
         | 
| 49 | 
            +
            - gestopft.gemspec
         | 
| 50 | 
            +
            - lib/gestopft.rb
         | 
| 29 51 | 
             
            - lib/gestopft/app.rb
         | 
| 52 | 
            +
            - lib/gestopft/core_ext.rb
         | 
| 30 53 | 
             
            - lib/gestopft/core_ext/array.rb
         | 
| 31 54 | 
             
            - lib/gestopft/core_ext/string.rb
         | 
| 32 55 | 
             
            - lib/gestopft/core_ext/symbol.rb
         | 
| 33 | 
            -
            - lib/gestopft/core_ext.rb
         | 
| 34 56 | 
             
            - lib/gestopft/option.rb
         | 
| 35 | 
            -
            - lib/gestopft.rb
         | 
| 57 | 
            +
            - lib/gestopft/version.rb
         | 
| 36 58 | 
             
            - spec/gestopft/option_spec.rb
         | 
| 37 59 | 
             
            - spec/gestopft_spec.rb
         | 
| 38 | 
            -
             | 
| 39 | 
            -
            homepage: http://github.com/aereal/gestopft
         | 
| 60 | 
            +
            homepage: https://github.com/aereal/gestopft
         | 
| 40 61 | 
             
            licenses: []
         | 
| 41 | 
            -
             | 
| 42 62 | 
             
            post_install_message: 
         | 
| 43 63 | 
             
            rdoc_options: []
         | 
| 44 | 
            -
             | 
| 45 | 
            -
             | 
| 46 | 
            -
             | 
| 47 | 
            -
            required_ruby_version: !ruby/object:Gem::Requirement 
         | 
| 64 | 
            +
            require_paths:
         | 
| 65 | 
            +
            - - lib
         | 
| 66 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 48 67 | 
             
              none: false
         | 
| 49 | 
            -
              requirements: | 
| 50 | 
            -
              - -  | 
| 51 | 
            -
                - !ruby/object:Gem::Version | 
| 52 | 
            -
                  version:  | 
| 53 | 
            -
             | 
| 68 | 
            +
              requirements:
         | 
| 69 | 
            +
              - - ! '>='
         | 
| 70 | 
            +
                - !ruby/object:Gem::Version
         | 
| 71 | 
            +
                  version: '0'
         | 
| 72 | 
            +
                  segments:
         | 
| 73 | 
            +
                  - 0
         | 
| 74 | 
            +
                  hash: -2301597943964023044
         | 
| 75 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 54 76 | 
             
              none: false
         | 
| 55 | 
            -
              requirements: | 
| 56 | 
            -
              - -  | 
| 57 | 
            -
                - !ruby/object:Gem::Version | 
| 58 | 
            -
                  version:  | 
| 77 | 
            +
              requirements:
         | 
| 78 | 
            +
              - - ! '>='
         | 
| 79 | 
            +
                - !ruby/object:Gem::Version
         | 
| 80 | 
            +
                  version: '0'
         | 
| 81 | 
            +
                  segments:
         | 
| 82 | 
            +
                  - 0
         | 
| 83 | 
            +
                  hash: -2301597943964023044
         | 
| 59 84 | 
             
            requirements: []
         | 
| 60 | 
            -
             | 
| 61 85 | 
             
            rubyforge_project: 
         | 
| 62 | 
            -
            rubygems_version: 1. | 
| 86 | 
            +
            rubygems_version: 1.8.17
         | 
| 63 87 | 
             
            signing_key: 
         | 
| 64 88 | 
             
            specification_version: 3
         | 
| 65 89 | 
             
            summary: Framework for CLI Application
         | 
| 66 | 
            -
            test_files: | 
| 67 | 
            -
             | 
| 90 | 
            +
            test_files:
         | 
| 91 | 
            +
            - spec/gestopft/option_spec.rb
         | 
| 92 | 
            +
            - spec/gestopft_spec.rb
         |