toys 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.
- checksums.yaml +5 -5
- data/LICENSE.md +29 -0
- data/README.md +36 -0
- data/bin/toys +31 -2
- data/lib/toys.rb +45 -1
- data/lib/toys/builder.rb +162 -0
- data/lib/toys/builtins/system.rb +32 -10
- data/lib/toys/cli.rb +83 -27
- data/lib/toys/context.rb +65 -13
- data/lib/toys/errors.rb +37 -2
- data/lib/toys/helpers/exec.rb +262 -31
- data/lib/toys/helpers/file_utils.rb +34 -4
- data/lib/toys/lookup.rb +152 -81
- data/lib/toys/template.rb +43 -14
- data/lib/toys/templates/clean.rb +67 -0
- data/lib/toys/templates/gem_build.rb +68 -36
- data/lib/toys/templates/minitest.rb +75 -29
- data/lib/toys/templates/rubocop.rb +66 -0
- data/lib/toys/templates/yardoc.rb +79 -0
- data/lib/toys/tool.rb +400 -215
- data/lib/toys/version.rb +34 -1
- metadata +13 -36
- data/lib/toys/parser.rb +0 -138
    
        data/lib/toys/version.rb
    CHANGED
    
    | @@ -1,3 +1,36 @@ | |
| 1 | 
            +
            # Copyright 2018 Daniel Azuma
         | 
| 2 | 
            +
            #
         | 
| 3 | 
            +
            # All rights reserved.
         | 
| 4 | 
            +
            #
         | 
| 5 | 
            +
            # Redistribution and use in source and binary forms, with or without
         | 
| 6 | 
            +
            # modification, are permitted provided that the following conditions are met:
         | 
| 7 | 
            +
            #
         | 
| 8 | 
            +
            # * Redistributions of source code must retain the above copyright notice,
         | 
| 9 | 
            +
            #   this list of conditions and the following disclaimer.
         | 
| 10 | 
            +
            # * Redistributions in binary form must reproduce the above copyright notice,
         | 
| 11 | 
            +
            #   this list of conditions and the following disclaimer in the documentation
         | 
| 12 | 
            +
            #   and/or other materials provided with the distribution.
         | 
| 13 | 
            +
            # * Neither the name of the copyright holder, nor the names of any other
         | 
| 14 | 
            +
            #   contributors to this software, may be used to endorse or promote products
         | 
| 15 | 
            +
            #   derived from this software without specific prior written permission.
         | 
| 16 | 
            +
            #
         | 
| 17 | 
            +
            # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
         | 
| 18 | 
            +
            # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
         | 
| 19 | 
            +
            # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
         | 
| 20 | 
            +
            # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
         | 
| 21 | 
            +
            # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
         | 
| 22 | 
            +
            # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
         | 
| 23 | 
            +
            # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
         | 
| 24 | 
            +
            # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
         | 
| 25 | 
            +
            # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
         | 
| 26 | 
            +
            # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
         | 
| 27 | 
            +
            # POSSIBILITY OF SUCH DAMAGE.
         | 
| 28 | 
            +
            ;
         | 
| 29 | 
            +
             | 
| 1 30 | 
             
            module Toys
         | 
| 2 | 
            -
               | 
| 31 | 
            +
              ##
         | 
| 32 | 
            +
              # Current version of Toys
         | 
| 33 | 
            +
              # @return [String]
         | 
| 34 | 
            +
              #
         | 
| 35 | 
            +
              VERSION = "0.2.2".freeze
         | 
| 3 36 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,29 +1,15 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: toys
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.2. | 
| 4 | 
            +
              version: 0.2.2
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Daniel Azuma
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2018-03- | 
| 11 | 
            +
            date: 2018-03-13 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 | 
            -
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            -
              name: bundler
         | 
| 15 | 
            -
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            -
                requirements:
         | 
| 17 | 
            -
                - - "~>"
         | 
| 18 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            -
                    version: '1.16'
         | 
| 20 | 
            -
              type: :development
         | 
| 21 | 
            -
              prerelease: false
         | 
| 22 | 
            -
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 | 
            -
                requirements:
         | 
| 24 | 
            -
                - - "~>"
         | 
| 25 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            -
                    version: '1.16'
         | 
| 27 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 28 14 | 
             
              name: minitest
         | 
| 29 15 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -67,33 +53,19 @@ dependencies: | |
| 67 53 | 
             
                  - !ruby/object:Gem::Version
         | 
| 68 54 | 
             
                    version: '5.2'
         | 
| 69 55 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 70 | 
            -
              name:  | 
| 71 | 
            -
              requirement: !ruby/object:Gem::Requirement
         | 
| 72 | 
            -
                requirements:
         | 
| 73 | 
            -
                - - "~>"
         | 
| 74 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 75 | 
            -
                    version: '12.0'
         | 
| 76 | 
            -
              type: :development
         | 
| 77 | 
            -
              prerelease: false
         | 
| 78 | 
            -
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 79 | 
            -
                requirements:
         | 
| 80 | 
            -
                - - "~>"
         | 
| 81 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 82 | 
            -
                    version: '12.0'
         | 
| 83 | 
            -
            - !ruby/object:Gem::Dependency
         | 
| 84 | 
            -
              name: rdoc
         | 
| 56 | 
            +
              name: rubocop
         | 
| 85 57 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 86 58 | 
             
                requirements:
         | 
| 87 59 | 
             
                - - "~>"
         | 
| 88 60 | 
             
                  - !ruby/object:Gem::Version
         | 
| 89 | 
            -
                    version:  | 
| 61 | 
            +
                    version: 0.53.0
         | 
| 90 62 | 
             
              type: :development
         | 
| 91 63 | 
             
              prerelease: false
         | 
| 92 64 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 93 65 | 
             
                requirements:
         | 
| 94 66 | 
             
                - - "~>"
         | 
| 95 67 | 
             
                  - !ruby/object:Gem::Version
         | 
| 96 | 
            -
                    version:  | 
| 68 | 
            +
                    version: 0.53.0
         | 
| 97 69 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 98 70 | 
             
              name: yard
         | 
| 99 71 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -116,8 +88,11 @@ executables: | |
| 116 88 | 
             
            extensions: []
         | 
| 117 89 | 
             
            extra_rdoc_files: []
         | 
| 118 90 | 
             
            files:
         | 
| 91 | 
            +
            - LICENSE.md
         | 
| 92 | 
            +
            - README.md
         | 
| 119 93 | 
             
            - bin/toys
         | 
| 120 94 | 
             
            - lib/toys.rb
         | 
| 95 | 
            +
            - lib/toys/builder.rb
         | 
| 121 96 | 
             
            - lib/toys/builtins/system.rb
         | 
| 122 97 | 
             
            - lib/toys/cli.rb
         | 
| 123 98 | 
             
            - lib/toys/context.rb
         | 
| @@ -125,10 +100,12 @@ files: | |
| 125 100 | 
             
            - lib/toys/helpers/exec.rb
         | 
| 126 101 | 
             
            - lib/toys/helpers/file_utils.rb
         | 
| 127 102 | 
             
            - lib/toys/lookup.rb
         | 
| 128 | 
            -
            - lib/toys/parser.rb
         | 
| 129 103 | 
             
            - lib/toys/template.rb
         | 
| 104 | 
            +
            - lib/toys/templates/clean.rb
         | 
| 130 105 | 
             
            - lib/toys/templates/gem_build.rb
         | 
| 131 106 | 
             
            - lib/toys/templates/minitest.rb
         | 
| 107 | 
            +
            - lib/toys/templates/rubocop.rb
         | 
| 108 | 
            +
            - lib/toys/templates/yardoc.rb
         | 
| 132 109 | 
             
            - lib/toys/tool.rb
         | 
| 133 110 | 
             
            - lib/toys/version.rb
         | 
| 134 111 | 
             
            homepage: https://github.com/dazuma/toys
         | 
| @@ -143,7 +120,7 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 143 120 | 
             
              requirements:
         | 
| 144 121 | 
             
              - - ">="
         | 
| 145 122 | 
             
                - !ruby/object:Gem::Version
         | 
| 146 | 
            -
                  version: 2. | 
| 123 | 
            +
                  version: 2.2.0
         | 
| 147 124 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 148 125 | 
             
              requirements:
         | 
| 149 126 | 
             
              - - ">="
         | 
| @@ -151,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 151 128 | 
             
                  version: '0'
         | 
| 152 129 | 
             
            requirements: []
         | 
| 153 130 | 
             
            rubyforge_project: 
         | 
| 154 | 
            -
            rubygems_version: 2. | 
| 131 | 
            +
            rubygems_version: 2.6.14
         | 
| 155 132 | 
             
            signing_key: 
         | 
| 156 133 | 
             
            specification_version: 4
         | 
| 157 134 | 
             
            summary: Command line tool framework
         | 
    
        data/lib/toys/parser.rb
    DELETED
    
    | @@ -1,138 +0,0 @@ | |
| 1 | 
            -
            module Toys
         | 
| 2 | 
            -
              class Parser
         | 
| 3 | 
            -
                def initialize(path, tool, remaining_words, priority, lookup)
         | 
| 4 | 
            -
                  @path = path
         | 
| 5 | 
            -
                  @tool = tool
         | 
| 6 | 
            -
                  @remaining_words = remaining_words
         | 
| 7 | 
            -
                  @priority = priority
         | 
| 8 | 
            -
                  @lookup = lookup
         | 
| 9 | 
            -
                end
         | 
| 10 | 
            -
             | 
| 11 | 
            -
                def name(word, alias_of: nil, &block)
         | 
| 12 | 
            -
                  word = word.to_s
         | 
| 13 | 
            -
                  subtool = @lookup.get_tool(@tool.full_name + [word], @priority)
         | 
| 14 | 
            -
                  return self if subtool.nil?
         | 
| 15 | 
            -
                  if alias_of
         | 
| 16 | 
            -
                    if block
         | 
| 17 | 
            -
                      raise Toys::ToysDefinitionError, "Cannot take a block with alias_of"
         | 
| 18 | 
            -
                    end
         | 
| 19 | 
            -
                    target = @tool.full_name + [alias_of.to_s]
         | 
| 20 | 
            -
                    target_tool = @lookup.lookup(target)
         | 
| 21 | 
            -
                    unless target_tool.full_name == target
         | 
| 22 | 
            -
                      raise Toys::ToysDefinitionError, "Alias target #{target.inspect} not found"
         | 
| 23 | 
            -
                    end
         | 
| 24 | 
            -
                    subtool.set_alias_target(target)
         | 
| 25 | 
            -
                    return self
         | 
| 26 | 
            -
                  end
         | 
| 27 | 
            -
                  next_remaining = @remaining_words
         | 
| 28 | 
            -
                  if next_remaining && !next_remaining.empty?
         | 
| 29 | 
            -
                    if next_remaining.first == word
         | 
| 30 | 
            -
                      next_remaining = next_remaining.slice(1..-1)
         | 
| 31 | 
            -
                    else
         | 
| 32 | 
            -
                      next_remaining = nil
         | 
| 33 | 
            -
                    end
         | 
| 34 | 
            -
                  end
         | 
| 35 | 
            -
                  Parser.parse(@path, subtool, next_remaining, @priority, @lookup, block)
         | 
| 36 | 
            -
                  self
         | 
| 37 | 
            -
                end
         | 
| 38 | 
            -
             | 
| 39 | 
            -
                def alias_as(word)
         | 
| 40 | 
            -
                  unless @tool.root?
         | 
| 41 | 
            -
                    alias_tool = @lookup.get_tool(@tool.full_name.slice(0..-2) + [word], @priority)
         | 
| 42 | 
            -
                    alias_tool.set_alias_target(@tool) if alias_tool
         | 
| 43 | 
            -
                  end
         | 
| 44 | 
            -
                  self
         | 
| 45 | 
            -
                end
         | 
| 46 | 
            -
             | 
| 47 | 
            -
                def alias_of(target)
         | 
| 48 | 
            -
                  target_tool = @lookup.lookup(target)
         | 
| 49 | 
            -
                  unless target_tool.full_name == target
         | 
| 50 | 
            -
                    raise Toys::ToysDefinitionError, "Alias target #{target.inspect} not found"
         | 
| 51 | 
            -
                  end
         | 
| 52 | 
            -
                  @tool.set_alias_target(target_tool)
         | 
| 53 | 
            -
                  self
         | 
| 54 | 
            -
                end
         | 
| 55 | 
            -
             | 
| 56 | 
            -
                def include(path)
         | 
| 57 | 
            -
                  @tool.yield_definition do
         | 
| 58 | 
            -
                    @lookup.include_path(path, @tool.full_name, @remaining_words, @priority)
         | 
| 59 | 
            -
                  end
         | 
| 60 | 
            -
                  self
         | 
| 61 | 
            -
                end
         | 
| 62 | 
            -
             | 
| 63 | 
            -
                def expand(template, opts={})
         | 
| 64 | 
            -
                  if template.is_a?(Symbol)
         | 
| 65 | 
            -
                    template = template.to_s
         | 
| 66 | 
            -
                    file_name = template.gsub(/([a-zA-Z])([A-Z])/){ |m| "#{$1}_#{$2.downcase}" }.downcase
         | 
| 67 | 
            -
                    require "toys/templates/#{file_name}"
         | 
| 68 | 
            -
                    const_name = template.gsub(/(^|_)([a-zA-Z0-9])/){ |m| $2.upcase }
         | 
| 69 | 
            -
                    template = Toys::Templates.const_get(const_name)
         | 
| 70 | 
            -
                  end
         | 
| 71 | 
            -
                  opts = template.opts_initializer.call(opts)
         | 
| 72 | 
            -
                  yield opts if block_given?
         | 
| 73 | 
            -
                  instance_exec(opts, &template.expander)
         | 
| 74 | 
            -
                  self
         | 
| 75 | 
            -
                end
         | 
| 76 | 
            -
             | 
| 77 | 
            -
                def long_desc(desc)
         | 
| 78 | 
            -
                  @tool.long_desc = desc
         | 
| 79 | 
            -
                  self
         | 
| 80 | 
            -
                end
         | 
| 81 | 
            -
             | 
| 82 | 
            -
                def short_desc(desc)
         | 
| 83 | 
            -
                  @tool.short_desc = desc
         | 
| 84 | 
            -
                  self
         | 
| 85 | 
            -
                end
         | 
| 86 | 
            -
             | 
| 87 | 
            -
                def switch(key, *switches, accept: nil, default: nil, doc: nil)
         | 
| 88 | 
            -
                  @tool.add_switch(key, *switches, accept: accept, default: default, doc: doc)
         | 
| 89 | 
            -
                  self
         | 
| 90 | 
            -
                end
         | 
| 91 | 
            -
             | 
| 92 | 
            -
                def required_arg(key, accept: nil, doc: nil)
         | 
| 93 | 
            -
                  @tool.add_required_arg(key, accept: accept, doc: doc)
         | 
| 94 | 
            -
                  self
         | 
| 95 | 
            -
                end
         | 
| 96 | 
            -
             | 
| 97 | 
            -
                def optional_arg(key, accept: nil, default: nil, doc: nil)
         | 
| 98 | 
            -
                  @tool.add_optional_arg(key, accept: accept, default: default, doc: doc)
         | 
| 99 | 
            -
                  self
         | 
| 100 | 
            -
                end
         | 
| 101 | 
            -
             | 
| 102 | 
            -
                def remaining_args(key, accept: nil, default: [], doc: nil)
         | 
| 103 | 
            -
                  @tool.set_remaining_args(key, accept: accept, default: default, doc: doc)
         | 
| 104 | 
            -
                  self
         | 
| 105 | 
            -
                end
         | 
| 106 | 
            -
             | 
| 107 | 
            -
                def execute(&block)
         | 
| 108 | 
            -
                  @tool.executor = block
         | 
| 109 | 
            -
                  self
         | 
| 110 | 
            -
                end
         | 
| 111 | 
            -
             | 
| 112 | 
            -
                def helper(name, &block)
         | 
| 113 | 
            -
                  @tool.add_helper(name, &block)
         | 
| 114 | 
            -
                  self
         | 
| 115 | 
            -
                end
         | 
| 116 | 
            -
             | 
| 117 | 
            -
                def use(mod)
         | 
| 118 | 
            -
                  @tool.use_helper_module(mod)
         | 
| 119 | 
            -
                  self
         | 
| 120 | 
            -
                end
         | 
| 121 | 
            -
             | 
| 122 | 
            -
                def _binding
         | 
| 123 | 
            -
                  binding
         | 
| 124 | 
            -
                end
         | 
| 125 | 
            -
             | 
| 126 | 
            -
                def self.parse(path, tool, remaining_words, priority, lookup, source)
         | 
| 127 | 
            -
                  parser = new(path, tool, remaining_words, priority, lookup)
         | 
| 128 | 
            -
                  tool.defining_from(path) do
         | 
| 129 | 
            -
                    if String === source
         | 
| 130 | 
            -
                      eval(source, parser._binding, path, 1)
         | 
| 131 | 
            -
                    elsif Proc === source
         | 
| 132 | 
            -
                      parser.instance_eval(&source)
         | 
| 133 | 
            -
                    end
         | 
| 134 | 
            -
                  end
         | 
| 135 | 
            -
                  tool
         | 
| 136 | 
            -
                end
         | 
| 137 | 
            -
              end
         | 
| 138 | 
            -
            end
         |