toys-core 0.3.7.1 → 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +10 -0
  3. data/README.md +1 -2
  4. data/lib/toys-core.rb +23 -8
  5. data/lib/toys/cli.rb +62 -23
  6. data/lib/toys/core_version.rb +1 -1
  7. data/lib/toys/definition/arg.rb +0 -2
  8. data/lib/toys/definition/flag.rb +2 -4
  9. data/lib/toys/definition/tool.rb +38 -36
  10. data/lib/toys/dsl/arg.rb +4 -0
  11. data/lib/toys/dsl/flag.rb +9 -5
  12. data/lib/toys/dsl/tool.rb +35 -28
  13. data/lib/toys/input_file.rb +2 -1
  14. data/lib/toys/loader.rb +97 -51
  15. data/lib/toys/middleware.rb +61 -87
  16. data/lib/toys/runner.rb +19 -2
  17. data/lib/toys/{middleware → standard_middleware}/add_verbosity_flags.rb +24 -8
  18. data/lib/toys/{middleware → standard_middleware}/handle_usage_errors.rb +4 -6
  19. data/lib/toys/{middleware → standard_middleware}/set_default_descriptions.rb +4 -4
  20. data/lib/toys/{middleware → standard_middleware}/show_help.rb +32 -16
  21. data/lib/toys/{middleware → standard_middleware}/show_root_version.rb +4 -5
  22. data/lib/toys/{helpers → standard_mixins}/exec.rb +8 -8
  23. data/lib/toys/{helpers → standard_mixins}/fileutils.rb +1 -1
  24. data/lib/toys/{helpers → standard_mixins}/highline.rb +2 -3
  25. data/lib/toys/{helpers → standard_mixins}/terminal.rb +2 -4
  26. data/lib/toys/tool.rb +3 -2
  27. data/lib/toys/utils/exec.rb +255 -82
  28. data/lib/toys/utils/gems.rb +3 -3
  29. data/lib/toys/utils/help_text.rb +0 -2
  30. data/lib/toys/utils/module_lookup.rb +60 -40
  31. data/lib/toys/utils/wrappable_string.rb +0 -2
  32. metadata +11 -19
  33. data/lib/toys/helpers.rb +0 -54
  34. data/lib/toys/middleware/base.rb +0 -99
  35. data/lib/toys/templates.rb +0 -55
  36. data/lib/toys/templates/clean.rb +0 -85
  37. data/lib/toys/templates/gem_build.rb +0 -125
  38. data/lib/toys/templates/minitest.rb +0 -125
  39. data/lib/toys/templates/rubocop.rb +0 -86
  40. data/lib/toys/templates/yardoc.rb +0 -101
@@ -1,125 +0,0 @@
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
-
30
- require "rubygems/package"
31
-
32
- module Toys
33
- module Templates
34
- ##
35
- # A template for tools that build and release gems
36
- #
37
- class GemBuild
38
- include Template
39
-
40
- ##
41
- # Default tool name
42
- # @return [String]
43
- #
44
- DEFAULT_TOOL_NAME = "build".freeze
45
-
46
- ##
47
- # Create the template settings for the GemBuild template.
48
- #
49
- # @param [String] name Name of the tool to create. Defaults to
50
- # {DEFAULT_TOOL_NAME}.
51
- # @param [String] gem_name Name of the gem to build. If not provided,
52
- # defaults to the first gemspec file it finds.
53
- # @param [Boolean] push_gem If true, pushes the built gem to rubygems.
54
- # @param [Boolean] tag If true, tags the git repo with the gem version.
55
- # @param [Boolean,String] push_tag If truthy, pushes the new tag to
56
- # a git remote. You may specify which remote by setting the value to
57
- # a string. Otherwise, if the value is simply `true`, the "origin"
58
- # remote is used by default.
59
- #
60
- def initialize(name: DEFAULT_TOOL_NAME,
61
- gem_name: nil,
62
- push_gem: false,
63
- tag: false,
64
- push_tag: false)
65
- @name = name
66
- @gem_name = gem_name
67
- @push_gem = push_gem
68
- @tag = tag
69
- @push_tag = push_tag
70
- end
71
-
72
- attr_accessor :name
73
- attr_accessor :gem_name
74
- attr_accessor :push_gem
75
- attr_accessor :tag
76
- attr_accessor :push_tag
77
-
78
- to_expand do |template|
79
- unless template.gem_name
80
- candidates = ::Dir.glob("*.gemspec")
81
- if candidates.empty?
82
- raise ToolDefinitionError, "Could not find a gemspec"
83
- end
84
- template.gem_name = candidates.first.sub(/\.gemspec$/, "")
85
- end
86
- task_type = template.push_gem ? "Release" : "Build"
87
-
88
- tool(template.name) do
89
- desc "#{task_type} the gem: #{template.gem_name}"
90
-
91
- flag :yes, "-y", "--yes", desc: "Do not ask for interactive confirmation"
92
-
93
- include :exec
94
- include :fileutils
95
- include :terminal
96
-
97
- run do
98
- configure_exec(exit_on_nonzero_status: true)
99
- gemspec = ::Gem::Specification.load "#{template.gem_name}.gemspec"
100
- version = gemspec.version
101
- gemfile = "#{template.gem_name}-#{version}.gem"
102
- ::Gem::Package.build gemspec
103
- mkdir_p "pkg"
104
- mv gemfile, "pkg"
105
- if template.push_gem
106
- if ::File.directory?(".git") && capture("git status -s").strip != ""
107
- logger.error "Cannot push the gem when there are uncommited changes"
108
- exit(1)
109
- end
110
- exit(1) unless option(:yes) || confirm("Release #{gemfile}?")
111
- sh "gem push pkg/#{gemfile}"
112
- if template.tag
113
- sh "git tag v#{version}"
114
- if template.push_tag
115
- template.push_tag = "origin" if template.push_tag == true
116
- sh "git push #{template.push_tag} v#{version}"
117
- end
118
- end
119
- end
120
- end
121
- end
122
- end
123
- end
124
- end
125
- end
@@ -1,125 +0,0 @@
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
-
30
- module Toys
31
- module Templates
32
- ##
33
- # A template for tools that run minitest
34
- #
35
- class Minitest
36
- include Template
37
-
38
- ##
39
- # Default tool name
40
- # @return [String]
41
- #
42
- DEFAULT_TOOL_NAME = "test".freeze
43
-
44
- ##
45
- # Default set of library paths
46
- # @return [Array<String>]
47
- #
48
- DEFAULT_LIBS = ["lib"].freeze
49
-
50
- ##
51
- # Default set of test file globs
52
- # @return [Array<String>]
53
- #
54
- DEFAULT_FILES = ["test/**/test*.rb"].freeze
55
-
56
- ##
57
- # Create the template settings for the Minitest template.
58
- #
59
- # @param [String] name Name of the tool to create. Defaults to
60
- # {DEFAULT_TOOL_NAME}.
61
- # @param [Array<String>] libs An array of library paths to add to the
62
- # ruby require path. Defaults to {DEFAULT_LIBS}.
63
- # @param [Array<String>] files An array of globs indicating the test
64
- # files to load. Defaults to {DEFAULT_FILES}.
65
- # @param [Boolean] warnings If true, runs tests with Ruby warnings.
66
- # Defaults to true.
67
- #
68
- def initialize(name: DEFAULT_TOOL_NAME,
69
- libs: DEFAULT_LIBS,
70
- files: DEFAULT_FILES,
71
- warnings: true)
72
- @name = name
73
- @libs = libs
74
- @files = files
75
- @warnings = warnings
76
- end
77
-
78
- attr_accessor :name
79
- attr_accessor :libs
80
- attr_accessor :files
81
- attr_accessor :warnings
82
-
83
- to_expand do |template|
84
- tool(template.name) do
85
- desc "Run minitest on the current project."
86
-
87
- include :exec
88
-
89
- flag :warnings, "-w", "--[no-]warnings",
90
- default: template.warnings,
91
- desc: "Turn on Ruby warnings (defaults to #{template.warnings})"
92
-
93
- remaining_args :tests, desc: "Paths to the tests to run (defaults to all tests)"
94
-
95
- run do
96
- ruby_args = []
97
- unless template.libs.empty?
98
- lib_path = template.libs.join(::File::PATH_SEPARATOR)
99
- ruby_args << "-I#{lib_path}"
100
- end
101
- ruby_args << "-w" if self[:warnings]
102
-
103
- tests = self[:tests]
104
- if tests.empty?
105
- Array(template.files).each do |pattern|
106
- tests.concat(::Dir.glob(pattern))
107
- end
108
- tests.uniq!
109
- end
110
-
111
- result = ruby(ruby_args, in_from: :controller) do |controller|
112
- tests.each do |file|
113
- controller.in.puts("load '#{file}'")
114
- end
115
- end
116
- if result.error?
117
- logger.error("Minitest failed!")
118
- exit(result.exit_code)
119
- end
120
- end
121
- end
122
- end
123
- end
124
- end
125
- end
@@ -1,86 +0,0 @@
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
-
30
- module Toys
31
- module Templates
32
- ##
33
- # A template for tools that run rubocop
34
- #
35
- class Rubocop
36
- include Template
37
-
38
- ##
39
- # Default tool name
40
- # @return [String]
41
- #
42
- DEFAULT_TOOL_NAME = "rubocop".freeze
43
-
44
- ##
45
- # Create the template settings for the Rubocop template.
46
- #
47
- # @param [String] name Name of the tool to create. Defaults to
48
- # {DEFAULT_TOOL_NAME}.
49
- # @param [Boolean] fail_on_error If true, exits with a nonzero code if
50
- # Rubocop fails. Defaults to true.
51
- # @param [Array<String>] options Additional options passed to the Rubocop
52
- # CLI.
53
- #
54
- def initialize(name: DEFAULT_TOOL_NAME,
55
- fail_on_error: true,
56
- options: [])
57
- @name = name
58
- @fail_on_error = fail_on_error
59
- @options = options
60
- end
61
-
62
- attr_accessor :name
63
- attr_accessor :fail_on_error
64
- attr_accessor :options
65
-
66
- to_expand do |template|
67
- tool(template.name) do
68
- desc "Run rubocop on the current project."
69
-
70
- include :exec
71
-
72
- run do
73
- require "rubocop"
74
- cli = ::RuboCop::CLI.new
75
- logger.info "Running RuboCop..."
76
- result = cli.run(template.options)
77
- if result.nonzero?
78
- logger.error "RuboCop failed!"
79
- exit(1) if template.fail_on_error
80
- end
81
- end
82
- end
83
- end
84
- end
85
- end
86
- end
@@ -1,101 +0,0 @@
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
-
30
- module Toys
31
- module Templates
32
- ##
33
- # A template for tools that run yardoc
34
- #
35
- class Yardoc
36
- include Template
37
-
38
- ##
39
- # Default tool name
40
- # @return [String]
41
- #
42
- DEFAULT_TOOL_NAME = "yardoc".freeze
43
-
44
- ##
45
- # Create the template settings for the Yardoc template.
46
- #
47
- # @param [String] name Name of the tool to create. Defaults to
48
- # {DEFAULT_TOOL_NAME}.
49
- # @param [Array<String>] files An array of globs indicating the files
50
- # to document.
51
- # @param [Array<String>] options Additional options passed to YARD
52
- # @param [Array<String>] stats_options Additional options passed to YARD
53
- # stats
54
- #
55
- def initialize(name: DEFAULT_TOOL_NAME,
56
- files: [],
57
- options: [],
58
- stats_options: [])
59
- @name = name
60
- @files = files
61
- @options = options
62
- @stats_options = stats_options
63
- end
64
-
65
- attr_accessor :name
66
- attr_accessor :files
67
- attr_accessor :options
68
- attr_accessor :stats_options
69
-
70
- to_expand do |template|
71
- tool(template.name) do
72
- desc "Run yardoc on the current project."
73
-
74
- include :exec
75
-
76
- run do
77
- require "yard"
78
- files = []
79
- patterns = Array(template.files)
80
- patterns = ["lib/**/*.rb"] if patterns.empty?
81
- patterns.each do |pattern|
82
- files.concat(::Dir.glob(pattern))
83
- end
84
- files.uniq!
85
-
86
- unless template.stats_options.empty?
87
- template.options << "--no-stats"
88
- template.stats_options << "--use-cache"
89
- end
90
-
91
- yardoc = ::YARD::CLI::Yardoc.new
92
- yardoc.run(*(template.options + files))
93
- unless template.stats_options.empty?
94
- ::YARD::CLI::Stats.run(*template.stats_options)
95
- end
96
- end
97
- end
98
- end
99
- end
100
- end
101
- end