scripting 0.2.1 → 0.2.2
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/VERSION +1 -1
- data/lib/scripting/commands.rb +16 -11
- data/scripting.gemspec +3 -3
- data/spec/commands_spec.rb +37 -5
- metadata +42 -47
    
        data/VERSION
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            0.2. | 
| 1 | 
            +
            0.2.2
         | 
    
        data/lib/scripting/commands.rb
    CHANGED
    
    | @@ -4,7 +4,8 @@ module Scripting | |
| 4 4 | 
             
                class Command
         | 
| 5 5 | 
             
                  attr_reader :name
         | 
| 6 6 |  | 
| 7 | 
            -
                  def initialize name
         | 
| 7 | 
            +
                  def initialize app, name
         | 
| 8 | 
            +
                    @app = app
         | 
| 8 9 | 
             
                    @name = name.to_s.downcase.to_sym
         | 
| 9 10 | 
             
                    @description = nil
         | 
| 10 11 | 
             
                    @work = lambda {} # noop by default
         | 
| @@ -28,7 +29,7 @@ module Scripting | |
| 28 29 | 
             
                  end
         | 
| 29 30 |  | 
| 30 31 | 
             
                  def run! *args
         | 
| 31 | 
            -
                    @ | 
| 32 | 
            +
                    @app.instance_exec(*args, &work)
         | 
| 32 33 | 
             
                  end
         | 
| 33 34 | 
             
                end
         | 
| 34 35 |  | 
| @@ -48,21 +49,25 @@ module Scripting | |
| 48 49 |  | 
| 49 50 | 
             
                    work do |*args|
         | 
| 50 51 | 
             
                      name = args.shift.downcase.to_sym rescue nil
         | 
| 51 | 
            -
                       | 
| 52 | 
            -
                      if command.nil?
         | 
| 53 | 
            -
                        help!
         | 
| 54 | 
            -
                        puts "\nCommand: #{name} is not known"
         | 
| 55 | 
            -
                        exit
         | 
| 56 | 
            -
                      end
         | 
| 57 | 
            -
             | 
| 58 | 
            -
                      command.run! *args
         | 
| 52 | 
            +
                      run_command! name, *args
         | 
| 59 53 | 
             
                    end
         | 
| 60 54 | 
             
                  end
         | 
| 61 55 | 
             
                end
         | 
| 62 56 |  | 
| 63 57 | 
             
                module InstanceMethods
         | 
| 64 58 | 
             
                  def command name, &blk
         | 
| 65 | 
            -
                    options.commands[name] = Command.new(name).describe(&blk)
         | 
| 59 | 
            +
                    options.commands[name] = Command.new(self, name).describe(&blk)
         | 
| 60 | 
            +
                  end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                  def run_command! name, *args
         | 
| 63 | 
            +
                    command = options.commands[name]
         | 
| 64 | 
            +
                    if command.nil?
         | 
| 65 | 
            +
                      help!
         | 
| 66 | 
            +
                      $stderr.puts "\n\nCommand: #{name} is not known"
         | 
| 67 | 
            +
                      exit
         | 
| 68 | 
            +
                    end
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                    command.run! *args
         | 
| 66 71 | 
             
                  end
         | 
| 67 72 | 
             
                end
         | 
| 68 73 | 
             
              end
         | 
    
        data/scripting.gemspec
    CHANGED
    
    | @@ -5,11 +5,11 @@ | |
| 5 5 |  | 
| 6 6 | 
             
            Gem::Specification.new do |s|
         | 
| 7 7 | 
             
              s.name = %q{scripting}
         | 
| 8 | 
            -
              s.version = "0.2. | 
| 8 | 
            +
              s.version = "0.2.2"
         | 
| 9 9 |  | 
| 10 10 | 
             
              s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
         | 
| 11 11 | 
             
              s.authors = ["sdeming"]
         | 
| 12 | 
            -
              s.date = %q{2011- | 
| 12 | 
            +
              s.date = %q{2011-05-19}
         | 
| 13 13 | 
             
              s.description = %q{Simplified command line scripting tool}
         | 
| 14 14 | 
             
              s.email = %q{sdeming@makefile.com}
         | 
| 15 15 | 
             
              s.extra_rdoc_files = [
         | 
| @@ -43,7 +43,7 @@ Gem::Specification.new do |s| | |
| 43 43 | 
             
              s.homepage = %q{http://github.com/sdeming/scripting}
         | 
| 44 44 | 
             
              s.licenses = ["MIT"]
         | 
| 45 45 | 
             
              s.require_paths = ["lib"]
         | 
| 46 | 
            -
              s.rubygems_version = %q{1.6. | 
| 46 | 
            +
              s.rubygems_version = %q{1.6.2}
         | 
| 47 47 | 
             
              s.summary = %q{Simplified command line scripting tool}
         | 
| 48 48 | 
             
              s.test_files = [
         | 
| 49 49 | 
             
                "examples/command.rb",
         | 
    
        data/spec/commands_spec.rb
    CHANGED
    
    | @@ -2,11 +2,11 @@ require 'spec_helper' | |
| 2 2 |  | 
| 3 3 | 
             
            describe Scripting::Commands do
         | 
| 4 4 | 
             
              it "should symbolize and downcase the command name" do
         | 
| 5 | 
            -
                Scripting::Commands::Command.new(:testing).name.should == :testing
         | 
| 6 | 
            -
                Scripting::Commands::Command.new(:Testing).name.should == :testing
         | 
| 7 | 
            -
                Scripting::Commands::Command.new('testing').name.should == :testing
         | 
| 8 | 
            -
                Scripting::Commands::Command.new("Testing").name.should == :testing
         | 
| 9 | 
            -
                Scripting::Commands::Command.new("TESTING").name.should == :testing
         | 
| 5 | 
            +
                Scripting::Commands::Command.new(nil, :testing).name.should == :testing
         | 
| 6 | 
            +
                Scripting::Commands::Command.new(nil, :Testing).name.should == :testing
         | 
| 7 | 
            +
                Scripting::Commands::Command.new(nil, 'testing').name.should == :testing
         | 
| 8 | 
            +
                Scripting::Commands::Command.new(nil, "Testing").name.should == :testing
         | 
| 9 | 
            +
                Scripting::Commands::Command.new(nil, "TESTING").name.should == :testing
         | 
| 10 10 | 
             
              end
         | 
| 11 11 | 
             
            end
         | 
| 12 12 |  | 
| @@ -21,6 +21,9 @@ describe Scripting::Commands::Command do | |
| 21 21 | 
             
                @app = Scripting::create_application do
         | 
| 22 22 | 
             
                  plugin Scripting::Commands
         | 
| 23 23 |  | 
| 24 | 
            +
                  def some_method; :some_method_return_value; end
         | 
| 25 | 
            +
                  options { some_option :some_option }
         | 
| 26 | 
            +
                  
         | 
| 24 27 | 
             
                  command :answer do
         | 
| 25 28 | 
             
                    description "The answer to life, the universe, and everything"
         | 
| 26 29 | 
             
                    work { puts 42 }
         | 
| @@ -35,6 +38,21 @@ describe Scripting::Commands::Command do | |
| 35 38 | 
             
                    description "Add two numbers"
         | 
| 36 39 | 
             
                    work { |a,b| puts a.to_f + b.to_f }
         | 
| 37 40 | 
             
                  end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                  command :context do
         | 
| 43 | 
            +
                    description "Print self.inspect"
         | 
| 44 | 
            +
                    work { print self.object_id }
         | 
| 45 | 
            +
                  end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                  command :call_some_method do
         | 
| 48 | 
            +
                    description "Call the some_method method"
         | 
| 49 | 
            +
                    work { print some_method.to_s }
         | 
| 50 | 
            +
                  end
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                  command :print_some_option do
         | 
| 53 | 
            +
                    description "Print some_option value"
         | 
| 54 | 
            +
                    work { print options.some_option.to_s }
         | 
| 55 | 
            +
                  end
         | 
| 38 56 | 
             
                end
         | 
| 39 57 | 
             
              end
         | 
| 40 58 |  | 
| @@ -61,4 +79,18 @@ describe Scripting::Commands::Command do | |
| 61 79 | 
             
                @stdout.should == "to infinity and beyond!\nHello world!\n"
         | 
| 62 80 | 
             
              end
         | 
| 63 81 |  | 
| 82 | 
            +
              it "should run in the context of the application" do
         | 
| 83 | 
            +
                @app.run! 'context'
         | 
| 84 | 
            +
                @stdout.should == @app.object_id.to_s
         | 
| 85 | 
            +
              end
         | 
| 86 | 
            +
             | 
| 87 | 
            +
              it "should call local application methods directly" do
         | 
| 88 | 
            +
                @app.run! 'call_some_method'
         | 
| 89 | 
            +
                @stdout.should == @app.some_method.to_s
         | 
| 90 | 
            +
              end
         | 
| 91 | 
            +
             | 
| 92 | 
            +
              it "should have direct access to options" do
         | 
| 93 | 
            +
                @app.run! 'print_some_option'
         | 
| 94 | 
            +
                @stdout.should == @app.options.some_option.to_s
         | 
| 95 | 
            +
              end
         | 
| 64 96 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,61 +1,58 @@ | |
| 1 | 
            -
            --- !ruby/object:Gem::Specification | 
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: scripting
         | 
| 3 | 
            -
            version: !ruby/object:Gem::Version | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.2.2
         | 
| 4 5 | 
             
              prerelease: 
         | 
| 5 | 
            -
              version: 0.2.1
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 | 
            -
            authors: | 
| 7 | 
            +
            authors:
         | 
| 8 8 | 
             
            - sdeming
         | 
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
             | 
| 13 | 
            -
            date: 2011-03-28 00:00:00 -04:00
         | 
| 12 | 
            +
            date: 2011-05-19 00:00:00.000000000 -04:00
         | 
| 14 13 | 
             
            default_executable: 
         | 
| 15 | 
            -
            dependencies: | 
| 16 | 
            -
            - !ruby/object:Gem::Dependency | 
| 14 | 
            +
            dependencies:
         | 
| 15 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 17 16 | 
             
              name: rspec
         | 
| 18 | 
            -
              requirement: & | 
| 17 | 
            +
              requirement: &24480720 !ruby/object:Gem::Requirement
         | 
| 19 18 | 
             
                none: false
         | 
| 20 | 
            -
                requirements: | 
| 21 | 
            -
                - -  | 
| 22 | 
            -
                  - !ruby/object:Gem::Version | 
| 19 | 
            +
                requirements:
         | 
| 20 | 
            +
                - - ! '>='
         | 
| 21 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 23 22 | 
             
                    version: 2.5.0
         | 
| 24 23 | 
             
              type: :development
         | 
| 25 24 | 
             
              prerelease: false
         | 
| 26 | 
            -
              version_requirements: * | 
| 27 | 
            -
            - !ruby/object:Gem::Dependency | 
| 25 | 
            +
              version_requirements: *24480720
         | 
| 26 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 28 27 | 
             
              name: jeweler
         | 
| 29 | 
            -
              requirement: & | 
| 28 | 
            +
              requirement: &24480220 !ruby/object:Gem::Requirement
         | 
| 30 29 | 
             
                none: false
         | 
| 31 | 
            -
                requirements: | 
| 30 | 
            +
                requirements:
         | 
| 32 31 | 
             
                - - ~>
         | 
| 33 | 
            -
                  - !ruby/object:Gem::Version | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 34 33 | 
             
                    version: 1.5.2
         | 
| 35 34 | 
             
              type: :development
         | 
| 36 35 | 
             
              prerelease: false
         | 
| 37 | 
            -
              version_requirements: * | 
| 38 | 
            -
            - !ruby/object:Gem::Dependency | 
| 36 | 
            +
              version_requirements: *24480220
         | 
| 37 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 39 38 | 
             
              name: rcov
         | 
| 40 | 
            -
              requirement: & | 
| 39 | 
            +
              requirement: &24479700 !ruby/object:Gem::Requirement
         | 
| 41 40 | 
             
                none: false
         | 
| 42 | 
            -
                requirements: | 
| 43 | 
            -
                - -  | 
| 44 | 
            -
                  - !ruby/object:Gem::Version | 
| 45 | 
            -
                    version:  | 
| 41 | 
            +
                requirements:
         | 
| 42 | 
            +
                - - ! '>='
         | 
| 43 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 44 | 
            +
                    version: '0'
         | 
| 46 45 | 
             
              type: :development
         | 
| 47 46 | 
             
              prerelease: false
         | 
| 48 | 
            -
              version_requirements: * | 
| 47 | 
            +
              version_requirements: *24479700
         | 
| 49 48 | 
             
            description: Simplified command line scripting tool
         | 
| 50 49 | 
             
            email: sdeming@makefile.com
         | 
| 51 50 | 
             
            executables: []
         | 
| 52 | 
            -
             | 
| 53 51 | 
             
            extensions: []
         | 
| 54 | 
            -
             | 
| 55 | 
            -
            extra_rdoc_files: 
         | 
| 52 | 
            +
            extra_rdoc_files:
         | 
| 56 53 | 
             
            - LICENSE.txt
         | 
| 57 54 | 
             
            - README.rdoc
         | 
| 58 | 
            -
            files: | 
| 55 | 
            +
            files:
         | 
| 59 56 | 
             
            - Gemfile
         | 
| 60 57 | 
             
            - Gemfile.lock
         | 
| 61 58 | 
             
            - LICENSE.txt
         | 
| @@ -80,36 +77,34 @@ files: | |
| 80 77 | 
             
            - spec/spec_helper.rb
         | 
| 81 78 | 
             
            has_rdoc: true
         | 
| 82 79 | 
             
            homepage: http://github.com/sdeming/scripting
         | 
| 83 | 
            -
            licenses: | 
| 80 | 
            +
            licenses:
         | 
| 84 81 | 
             
            - MIT
         | 
| 85 82 | 
             
            post_install_message: 
         | 
| 86 83 | 
             
            rdoc_options: []
         | 
| 87 | 
            -
             | 
| 88 | 
            -
            require_paths: 
         | 
| 84 | 
            +
            require_paths:
         | 
| 89 85 | 
             
            - lib
         | 
| 90 | 
            -
            required_ruby_version: !ruby/object:Gem::Requirement | 
| 86 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 91 87 | 
             
              none: false
         | 
| 92 | 
            -
              requirements: | 
| 93 | 
            -
              - -  | 
| 94 | 
            -
                - !ruby/object:Gem::Version | 
| 95 | 
            -
                   | 
| 96 | 
            -
                  segments: | 
| 88 | 
            +
              requirements:
         | 
| 89 | 
            +
              - - ! '>='
         | 
| 90 | 
            +
                - !ruby/object:Gem::Version
         | 
| 91 | 
            +
                  version: '0'
         | 
| 92 | 
            +
                  segments:
         | 
| 97 93 | 
             
                  - 0
         | 
| 98 | 
            -
                   | 
| 99 | 
            -
            required_rubygems_version: !ruby/object:Gem::Requirement | 
| 94 | 
            +
                  hash: 2683478235931159130
         | 
| 95 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 100 96 | 
             
              none: false
         | 
| 101 | 
            -
              requirements: | 
| 102 | 
            -
              - -  | 
| 103 | 
            -
                - !ruby/object:Gem::Version | 
| 104 | 
            -
                  version:  | 
| 97 | 
            +
              requirements:
         | 
| 98 | 
            +
              - - ! '>='
         | 
| 99 | 
            +
                - !ruby/object:Gem::Version
         | 
| 100 | 
            +
                  version: '0'
         | 
| 105 101 | 
             
            requirements: []
         | 
| 106 | 
            -
             | 
| 107 102 | 
             
            rubyforge_project: 
         | 
| 108 | 
            -
            rubygems_version: 1.6. | 
| 103 | 
            +
            rubygems_version: 1.6.2
         | 
| 109 104 | 
             
            signing_key: 
         | 
| 110 105 | 
             
            specification_version: 3
         | 
| 111 106 | 
             
            summary: Simplified command line scripting tool
         | 
| 112 | 
            -
            test_files: | 
| 107 | 
            +
            test_files:
         | 
| 113 108 | 
             
            - examples/command.rb
         | 
| 114 109 | 
             
            - examples/simple.rb
         | 
| 115 110 | 
             
            - spec/app_defaults_spec.rb
         |