toys-core 0.9.4 → 0.10.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.
- checksums.yaml +4 -4
- data/.yardopts +2 -1
- data/CHANGELOG.md +30 -0
- data/LICENSE.md +1 -1
- data/README.md +3 -3
- data/lib/toys-core.rb +11 -21
- data/lib/toys/acceptor.rb +0 -21
- data/lib/toys/arg_parser.rb +1 -22
- data/lib/toys/cli.rb +102 -70
- data/lib/toys/compat.rb +49 -41
- data/lib/toys/completion.rb +0 -21
- data/lib/toys/context.rb +0 -23
- data/lib/toys/core.rb +1 -22
- data/lib/toys/dsl/flag.rb +0 -21
- data/lib/toys/dsl/flag_group.rb +0 -21
- data/lib/toys/dsl/positional_arg.rb +0 -21
- data/lib/toys/dsl/tool.rb +135 -51
- data/lib/toys/errors.rb +0 -21
- data/lib/toys/flag.rb +0 -21
- data/lib/toys/flag_group.rb +0 -21
- data/lib/toys/input_file.rb +0 -21
- data/lib/toys/loader.rb +41 -78
- data/lib/toys/middleware.rb +146 -77
- data/lib/toys/mixin.rb +0 -21
- data/lib/toys/module_lookup.rb +3 -26
- data/lib/toys/positional_arg.rb +0 -21
- data/lib/toys/source_info.rb +49 -38
- data/lib/toys/standard_middleware/add_verbosity_flags.rb +0 -23
- data/lib/toys/standard_middleware/apply_config.rb +42 -0
- data/lib/toys/standard_middleware/handle_usage_errors.rb +7 -28
- data/lib/toys/standard_middleware/set_default_descriptions.rb +0 -23
- data/lib/toys/standard_middleware/show_help.rb +0 -23
- data/lib/toys/standard_middleware/show_root_version.rb +0 -23
- data/lib/toys/standard_mixins/bundler.rb +89 -0
- data/lib/toys/standard_mixins/exec.rb +124 -35
- data/lib/toys/standard_mixins/fileutils.rb +0 -21
- data/lib/toys/standard_mixins/gems.rb +2 -24
- data/lib/toys/standard_mixins/highline.rb +0 -21
- data/lib/toys/standard_mixins/terminal.rb +0 -21
- data/lib/toys/template.rb +0 -21
- data/lib/toys/tool.rb +22 -34
- data/lib/toys/utils/completion_engine.rb +0 -21
- data/lib/toys/utils/exec.rb +1 -21
- data/lib/toys/utils/gems.rb +174 -63
- data/lib/toys/utils/help_text.rb +0 -21
- data/lib/toys/utils/terminal.rb +46 -37
- data/lib/toys/wrappable_string.rb +0 -21
- metadata +25 -9
data/lib/toys/mixin.rb
CHANGED
@@ -1,26 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright 2019 Daniel Azuma
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
# of this software and associated documentation files (the "Software"), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in
|
13
|
-
# all copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
20
|
-
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
21
|
-
# IN THE SOFTWARE.
|
22
|
-
;
|
23
|
-
|
24
3
|
module Toys
|
25
4
|
##
|
26
5
|
# A mixin definition. Mixin modules should include this module.
|
data/lib/toys/module_lookup.rb
CHANGED
@@ -1,26 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright 2019 Daniel Azuma
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
# of this software and associated documentation files (the "Software"), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in
|
13
|
-
# all copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
20
|
-
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
21
|
-
# IN THE SOFTWARE.
|
22
|
-
;
|
23
|
-
|
24
3
|
require "monitor"
|
25
4
|
|
26
5
|
module Toys
|
@@ -73,13 +52,11 @@ module Toys
|
|
73
52
|
end
|
74
53
|
end
|
75
54
|
|
76
|
-
include ::MonitorMixin
|
77
|
-
|
78
55
|
##
|
79
56
|
# Create an empty ModuleLookup
|
80
57
|
#
|
81
58
|
def initialize
|
82
|
-
|
59
|
+
@mutex = ::Monitor.new
|
83
60
|
@paths = []
|
84
61
|
@paths_locked = false
|
85
62
|
end
|
@@ -96,7 +73,7 @@ module Toys
|
|
96
73
|
#
|
97
74
|
def add_path(path_base, module_base: nil, high_priority: false)
|
98
75
|
module_base ||= ModuleLookup.path_to_module(path_base)
|
99
|
-
synchronize do
|
76
|
+
@mutex.synchronize do
|
100
77
|
raise "You cannot add a path after a lookup has already occurred." if @paths_locked
|
101
78
|
if high_priority
|
102
79
|
@paths.unshift([path_base, module_base])
|
@@ -114,7 +91,7 @@ module Toys
|
|
114
91
|
# @return [Module] The specified module
|
115
92
|
#
|
116
93
|
def lookup(name)
|
117
|
-
synchronize do
|
94
|
+
@mutex.synchronize do
|
118
95
|
@paths_locked = true
|
119
96
|
@paths.each do |path_base, module_base|
|
120
97
|
path = "#{path_base}/#{ModuleLookup.to_path_name(name)}"
|
data/lib/toys/positional_arg.rb
CHANGED
@@ -1,26 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright 2019 Daniel Azuma
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
# of this software and associated documentation files (the "Software"), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in
|
13
|
-
# all copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
20
|
-
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
21
|
-
# IN THE SOFTWARE.
|
22
|
-
;
|
23
|
-
|
24
3
|
module Toys
|
25
4
|
##
|
26
5
|
# Representation of a formal positional argument
|
data/lib/toys/source_info.rb
CHANGED
@@ -1,26 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright 2019 Daniel Azuma
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
# of this software and associated documentation files (the "Software"), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in
|
13
|
-
# all copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
20
|
-
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
21
|
-
# IN THE SOFTWARE.
|
22
|
-
;
|
23
|
-
|
24
3
|
module Toys
|
25
4
|
##
|
26
5
|
# Information about source toys directories and files.
|
@@ -30,19 +9,17 @@ module Toys
|
|
30
9
|
# Create a SourceInfo.
|
31
10
|
# @private
|
32
11
|
#
|
33
|
-
def initialize(parent, context_directory,
|
12
|
+
def initialize(parent, context_directory, source_type, source_path, source_proc,
|
13
|
+
source_name, data_dir, lib_dir)
|
34
14
|
@parent = parent
|
35
15
|
@context_directory = context_directory
|
36
|
-
@source = source
|
37
16
|
@source_type = source_type
|
38
|
-
@
|
39
|
-
@
|
17
|
+
@source = source_type == :proc ? source_proc : source_path
|
18
|
+
@source_path = source_path
|
19
|
+
@source_proc = source_proc
|
40
20
|
@source_name = source_name
|
41
|
-
@data_dir =
|
42
|
-
|
43
|
-
dir = ::File.join(::File.dirname(@source_path), data_dir_name)
|
44
|
-
dir if ::File.directory?(dir) && ::File.readable?(dir)
|
45
|
-
end
|
21
|
+
@data_dir = data_dir
|
22
|
+
@lib_dir = lib_dir
|
46
23
|
end
|
47
24
|
|
48
25
|
##
|
@@ -82,7 +59,7 @@ module Toys
|
|
82
59
|
# The path of the current source file or directory.
|
83
60
|
#
|
84
61
|
# @return [String] The source path
|
85
|
-
# @return [nil] if this source
|
62
|
+
# @return [nil] if this source has no file system path.
|
86
63
|
#
|
87
64
|
attr_reader :source_path
|
88
65
|
|
@@ -90,7 +67,7 @@ module Toys
|
|
90
67
|
# The source proc.
|
91
68
|
#
|
92
69
|
# @return [Proc] The source proc
|
93
|
-
# @return [nil] if this source
|
70
|
+
# @return [nil] if this source has no proc.
|
94
71
|
#
|
95
72
|
attr_reader :source_proc
|
96
73
|
|
@@ -126,16 +103,30 @@ module Toys
|
|
126
103
|
parent&.find_data(path, type: type)
|
127
104
|
end
|
128
105
|
|
106
|
+
##
|
107
|
+
# Apply all lib paths in order from high to low priority
|
108
|
+
#
|
109
|
+
# @return [self]
|
110
|
+
#
|
111
|
+
def apply_lib_paths
|
112
|
+
parent&.apply_lib_paths
|
113
|
+
$LOAD_PATH.unshift(@lib_dir) if @lib_dir && !$LOAD_PATH.include?(@lib_dir)
|
114
|
+
self
|
115
|
+
end
|
116
|
+
|
129
117
|
##
|
130
118
|
# Create a child SourceInfo relative to the parent path.
|
131
119
|
# @private
|
132
120
|
#
|
133
|
-
def relative_child(filename, data_dir_name)
|
134
|
-
raise "
|
121
|
+
def relative_child(filename, data_dir_name, lib_dir_name)
|
122
|
+
raise "no parent path for relative_child" unless source_path
|
135
123
|
child_path = ::File.join(source_path, filename)
|
136
124
|
child_path, type = SourceInfo.check_path(child_path, true)
|
137
125
|
return nil unless child_path
|
138
|
-
SourceInfo.
|
126
|
+
data_dir = SourceInfo.find_special_dir(type, child_path, data_dir_name)
|
127
|
+
lib_dir = SourceInfo.find_special_dir(type, child_path, lib_dir_name)
|
128
|
+
SourceInfo.new(self, context_directory, type, child_path, source_proc, child_path,
|
129
|
+
data_dir, lib_dir)
|
139
130
|
end
|
140
131
|
|
141
132
|
##
|
@@ -144,7 +135,16 @@ module Toys
|
|
144
135
|
#
|
145
136
|
def absolute_child(child_path)
|
146
137
|
child_path, type = SourceInfo.check_path(child_path, false)
|
147
|
-
SourceInfo.new(self, context_directory, child_path,
|
138
|
+
SourceInfo.new(self, context_directory, type, child_path, source_proc, child_path, nil, nil)
|
139
|
+
end
|
140
|
+
|
141
|
+
##
|
142
|
+
# Create a proc child SourceInfo
|
143
|
+
# @private
|
144
|
+
#
|
145
|
+
def proc_child(child_proc, source_name = nil)
|
146
|
+
source_name ||= self.source_name
|
147
|
+
SourceInfo.new(self, context_directory, :proc, source_path, child_proc, source_name, nil, nil)
|
148
148
|
end
|
149
149
|
|
150
150
|
##
|
@@ -154,7 +154,7 @@ module Toys
|
|
154
154
|
def self.create_path_root(source_path)
|
155
155
|
source_path, type = check_path(source_path, false)
|
156
156
|
context_directory = ::File.dirname(source_path)
|
157
|
-
new(nil, context_directory, source_path,
|
157
|
+
new(nil, context_directory, type, source_path, nil, source_path, nil, nil)
|
158
158
|
end
|
159
159
|
|
160
160
|
##
|
@@ -162,7 +162,7 @@ module Toys
|
|
162
162
|
# @private
|
163
163
|
#
|
164
164
|
def self.create_proc_root(source_proc, source_name)
|
165
|
-
new(nil, nil,
|
165
|
+
new(nil, nil, :proc, nil, source_proc, source_name, nil, nil)
|
166
166
|
end
|
167
167
|
|
168
168
|
##
|
@@ -188,5 +188,16 @@ module Toys
|
|
188
188
|
[nil, nil]
|
189
189
|
end
|
190
190
|
end
|
191
|
+
|
192
|
+
##
|
193
|
+
# Determine the data directory path, if any.
|
194
|
+
# @private
|
195
|
+
#
|
196
|
+
def self.find_special_dir(type, source_path, dir_name)
|
197
|
+
return nil if source_path.nil? || dir_name.nil?
|
198
|
+
source_path = ::File.dirname(source_path) if type == :file
|
199
|
+
dir = ::File.join(source_path, dir_name)
|
200
|
+
dir if ::File.directory?(dir) && ::File.readable?(dir)
|
201
|
+
end
|
191
202
|
end
|
192
203
|
end
|
@@ -1,26 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright 2019 Daniel Azuma
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
# of this software and associated documentation files (the "Software"), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in
|
13
|
-
# all copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
20
|
-
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
21
|
-
# IN THE SOFTWARE.
|
22
|
-
;
|
23
|
-
|
24
3
|
module Toys
|
25
4
|
module StandardMiddleware
|
26
5
|
##
|
@@ -31,8 +10,6 @@ module Toys
|
|
31
10
|
# {Toys::Context::Key::VERBOSITY}, and, thus, the logger level.
|
32
11
|
#
|
33
12
|
class AddVerbosityFlags
|
34
|
-
include Middleware
|
35
|
-
|
36
13
|
##
|
37
14
|
# Default verbose flags
|
38
15
|
# @return [Array<String>]
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Toys
|
4
|
+
module StandardMiddleware
|
5
|
+
##
|
6
|
+
# A middleware that applies the given block to all tool configurations.
|
7
|
+
#
|
8
|
+
class ApplyConfig
|
9
|
+
##
|
10
|
+
# Create an ApplyConfig middleware
|
11
|
+
#
|
12
|
+
# @param parent_source [Toys::SourceInfo] The SourceInfo corresponding to
|
13
|
+
# the source where this block is provided, or `nil` (the default) if
|
14
|
+
# the block does not come from a Toys file.
|
15
|
+
# @param source_name [String] A user-visible name for the source, or
|
16
|
+
# `nil` to use the default.
|
17
|
+
# @param block [Proc] The configuration to apply.
|
18
|
+
#
|
19
|
+
def initialize(parent_source: nil, source_name: nil, &block)
|
20
|
+
@source_info =
|
21
|
+
if parent_source
|
22
|
+
parent_source.proc_child(block, source_name)
|
23
|
+
else
|
24
|
+
SourceInfo.create_proc_root(block, source_name)
|
25
|
+
end
|
26
|
+
@block = block
|
27
|
+
end
|
28
|
+
|
29
|
+
##
|
30
|
+
# Appends the configuration block.
|
31
|
+
# @private
|
32
|
+
#
|
33
|
+
def config(tool, _loader)
|
34
|
+
tool_class = tool.tool_class
|
35
|
+
DSL::Tool.prepare(tool_class, nil, @source_info) do
|
36
|
+
tool_class.class_eval(&@block)
|
37
|
+
end
|
38
|
+
yield
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -1,26 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright 2019 Daniel Azuma
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
# of this software and associated documentation files (the "Software"), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in
|
13
|
-
# all copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
20
|
-
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
21
|
-
# IN THE SOFTWARE.
|
22
|
-
;
|
23
|
-
|
24
3
|
module Toys
|
25
4
|
module StandardMiddleware
|
26
5
|
##
|
@@ -30,8 +9,6 @@ module Toys
|
|
30
9
|
# the short help string, and terminates execution with an error code.
|
31
10
|
#
|
32
11
|
class HandleUsageErrors
|
33
|
-
include Middleware
|
34
|
-
|
35
12
|
##
|
36
13
|
# Exit code for usage error. (2 by convention)
|
37
14
|
# @return [Integer]
|
@@ -49,9 +26,9 @@ module Toys
|
|
49
26
|
# a tty. Default is `nil`.
|
50
27
|
#
|
51
28
|
def initialize(exit_code: nil, stream: $stderr, styled_output: nil)
|
52
|
-
require "toys/utils/terminal"
|
53
29
|
@exit_code = exit_code || USAGE_ERROR_EXIT_CODE
|
54
|
-
@
|
30
|
+
@stream = stream
|
31
|
+
@styled_output = styled_output
|
55
32
|
end
|
56
33
|
|
57
34
|
##
|
@@ -61,11 +38,13 @@ module Toys
|
|
61
38
|
def run(context)
|
62
39
|
yield
|
63
40
|
rescue ArgParsingError => e
|
41
|
+
require "toys/utils/terminal"
|
64
42
|
require "toys/utils/help_text"
|
65
43
|
help_text = Utils::HelpText.from_context(context)
|
66
|
-
|
67
|
-
|
68
|
-
|
44
|
+
terminal = Utils::Terminal.new(output: @stream, styled: @styled_output)
|
45
|
+
terminal.puts(e.usage_errors.join("\n"), :bright_red, :bold)
|
46
|
+
terminal.puts("")
|
47
|
+
terminal.puts(help_text.usage_string(wrap_width: terminal.width))
|
69
48
|
Context.exit(@exit_code)
|
70
49
|
end
|
71
50
|
end
|
@@ -1,26 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright 2019 Daniel Azuma
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
# of this software and associated documentation files (the "Software"), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in
|
13
|
-
# all copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
20
|
-
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
21
|
-
# IN THE SOFTWARE.
|
22
|
-
;
|
23
|
-
|
24
3
|
module Toys
|
25
4
|
module StandardMiddleware
|
26
5
|
##
|
@@ -32,8 +11,6 @@ module Toys
|
|
32
11
|
# you can override methods to modify the description generation logic.
|
33
12
|
#
|
34
13
|
class SetDefaultDescriptions
|
35
|
-
include Middleware
|
36
|
-
|
37
14
|
##
|
38
15
|
# The default description for tools.
|
39
16
|
# @return [String]
|
@@ -1,26 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright 2019 Daniel Azuma
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
# of this software and associated documentation files (the "Software"), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in
|
13
|
-
# all copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
20
|
-
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
21
|
-
# IN THE SOFTWARE.
|
22
|
-
;
|
23
|
-
|
24
3
|
module Toys
|
25
4
|
module StandardMiddleware
|
26
5
|
##
|
@@ -34,8 +13,6 @@ module Toys
|
|
34
13
|
# middleware can also search for keywords in its subtools.
|
35
14
|
#
|
36
15
|
class ShowHelp
|
37
|
-
include Middleware
|
38
|
-
|
39
16
|
##
|
40
17
|
# Default help flags
|
41
18
|
# @return [Array<String>]
|