toys-core 0.11.5 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +62 -0
- data/LICENSE.md +1 -1
- data/README.md +5 -2
- data/docs/guide.md +1 -1
- data/lib/toys/acceptor.rb +13 -4
- data/lib/toys/arg_parser.rb +7 -7
- data/lib/toys/cli.rb +170 -120
- data/lib/toys/compat.rb +71 -23
- data/lib/toys/completion.rb +18 -6
- data/lib/toys/context.rb +24 -15
- data/lib/toys/core.rb +6 -2
- data/lib/toys/dsl/base.rb +87 -0
- data/lib/toys/dsl/flag.rb +26 -20
- data/lib/toys/dsl/flag_group.rb +18 -14
- data/lib/toys/dsl/internal.rb +206 -0
- data/lib/toys/dsl/positional_arg.rb +26 -16
- data/lib/toys/dsl/tool.rb +180 -218
- data/lib/toys/errors.rb +64 -8
- data/lib/toys/flag.rb +662 -656
- data/lib/toys/flag_group.rb +24 -10
- data/lib/toys/input_file.rb +13 -7
- data/lib/toys/loader.rb +293 -140
- data/lib/toys/middleware.rb +46 -22
- data/lib/toys/mixin.rb +10 -8
- data/lib/toys/positional_arg.rb +21 -20
- data/lib/toys/settings.rb +914 -0
- data/lib/toys/source_info.rb +147 -35
- data/lib/toys/standard_middleware/add_verbosity_flags.rb +2 -0
- data/lib/toys/standard_middleware/apply_config.rb +6 -4
- data/lib/toys/standard_middleware/handle_usage_errors.rb +1 -0
- data/lib/toys/standard_middleware/set_default_descriptions.rb +19 -18
- data/lib/toys/standard_middleware/show_help.rb +19 -5
- data/lib/toys/standard_middleware/show_root_version.rb +2 -0
- data/lib/toys/standard_mixins/bundler.rb +24 -15
- data/lib/toys/standard_mixins/exec.rb +43 -34
- data/lib/toys/standard_mixins/fileutils.rb +3 -1
- data/lib/toys/standard_mixins/gems.rb +21 -17
- data/lib/toys/standard_mixins/git_cache.rb +46 -0
- data/lib/toys/standard_mixins/highline.rb +8 -8
- data/lib/toys/standard_mixins/terminal.rb +5 -5
- data/lib/toys/standard_mixins/xdg.rb +56 -0
- data/lib/toys/template.rb +11 -9
- data/lib/toys/{tool.rb → tool_definition.rb} +292 -226
- data/lib/toys/utils/completion_engine.rb +7 -2
- data/lib/toys/utils/exec.rb +162 -132
- data/lib/toys/utils/gems.rb +85 -60
- data/lib/toys/utils/git_cache.rb +813 -0
- data/lib/toys/utils/help_text.rb +117 -37
- data/lib/toys/utils/terminal.rb +11 -3
- data/lib/toys/utils/xdg.rb +293 -0
- data/lib/toys/wrappable_string.rb +9 -2
- data/lib/toys-core.rb +18 -6
- metadata +14 -7
data/lib/toys/mixin.rb
CHANGED
@@ -9,7 +9,7 @@ module Toys
|
|
9
9
|
# class, so it has access to the same methods that can be called by the tool,
|
10
10
|
# such as {Toys::Context#get}.
|
11
11
|
#
|
12
|
-
#
|
12
|
+
# ### Usage
|
13
13
|
#
|
14
14
|
# To create a mixin, define a module, and include this module. Then define
|
15
15
|
# the methods you want to be available.
|
@@ -34,7 +34,7 @@ module Toys
|
|
34
34
|
# methods specific to the mixin. Define the inclusion block by calling
|
35
35
|
# {Toys::Mixin::ModuleMethods#on_include}.
|
36
36
|
#
|
37
|
-
#
|
37
|
+
# ### Example
|
38
38
|
#
|
39
39
|
# This is an example that implements a simple counter. Whenever the counter
|
40
40
|
# is incremented, a log message is emitted. The tool can also retrieve the
|
@@ -92,12 +92,6 @@ module Toys
|
|
92
92
|
mixin_mod
|
93
93
|
end
|
94
94
|
|
95
|
-
## @private
|
96
|
-
def self.included(mod)
|
97
|
-
return if mod.respond_to?(:on_initialize)
|
98
|
-
mod.extend(ModuleMethods)
|
99
|
-
end
|
100
|
-
|
101
95
|
##
|
102
96
|
# Methods that will be added to a mixin module object.
|
103
97
|
#
|
@@ -148,5 +142,13 @@ module Toys
|
|
148
142
|
#
|
149
143
|
attr_accessor :inclusion
|
150
144
|
end
|
145
|
+
|
146
|
+
##
|
147
|
+
# @private
|
148
|
+
#
|
149
|
+
def self.included(mod)
|
150
|
+
return if mod.respond_to?(:on_initialize)
|
151
|
+
mod.extend(ModuleMethods)
|
152
|
+
end
|
151
153
|
end
|
152
154
|
end
|
data/lib/toys/positional_arg.rb
CHANGED
@@ -5,23 +5,6 @@ module Toys
|
|
5
5
|
# Representation of a formal positional argument
|
6
6
|
#
|
7
7
|
class PositionalArg
|
8
|
-
##
|
9
|
-
# Create a PositionalArg definition.
|
10
|
-
# This argument list is subject to change. Use {Toys::PositionalArg.create}
|
11
|
-
# instead for a more stable interface.
|
12
|
-
# @private
|
13
|
-
#
|
14
|
-
def initialize(key, type, acceptor, default, completion, desc, long_desc, display_name)
|
15
|
-
@key = key
|
16
|
-
@type = type
|
17
|
-
@acceptor = Acceptor.create(acceptor)
|
18
|
-
@default = default
|
19
|
-
@completion = Completion.create(completion, **{})
|
20
|
-
@desc = WrappableString.make(desc)
|
21
|
-
@long_desc = WrappableString.make_array(long_desc)
|
22
|
-
@display_name = display_name || key.to_s.tr("-", "_").gsub(/\W/, "").upcase
|
23
|
-
end
|
24
|
-
|
25
8
|
##
|
26
9
|
# Create a PositionalArg definition.
|
27
10
|
#
|
@@ -37,11 +20,11 @@ module Toys
|
|
37
20
|
# @param display_name [String] A name to use for display (in help text and
|
38
21
|
# error reports). Defaults to the key in upper case.
|
39
22
|
# @param desc [String,Array<String>,Toys::WrappableString] Short
|
40
|
-
# description for the flag. See {Toys::
|
23
|
+
# description for the flag. See {Toys::ToolDefintion#desc} for a
|
41
24
|
# description of the allowed formats. Defaults to the empty string.
|
42
25
|
# @param long_desc [Array<String,Array<String>,Toys::WrappableString>]
|
43
|
-
# Long description for the flag. See {Toys::
|
44
|
-
# a description of the allowed formats. (But note that this param
|
26
|
+
# Long description for the flag. See {Toys::ToolDefintion#long_desc}
|
27
|
+
# for a description of the allowed formats. (But note that this param
|
45
28
|
# takes an Array of description lines, rather than a series of
|
46
29
|
# arguments.) Defaults to the empty array.
|
47
30
|
# @return [Toys::PositionalArg]
|
@@ -159,5 +142,23 @@ module Toys
|
|
159
142
|
@long_desc.concat(WrappableString.make_array(long_desc))
|
160
143
|
self
|
161
144
|
end
|
145
|
+
|
146
|
+
##
|
147
|
+
# Create a PositionalArg definition.
|
148
|
+
# This argument list is subject to change. Use {Toys::PositionalArg.create}
|
149
|
+
# instead for a more stable interface.
|
150
|
+
#
|
151
|
+
# @private
|
152
|
+
#
|
153
|
+
def initialize(key, type, acceptor, default, completion, desc, long_desc, display_name)
|
154
|
+
@key = key
|
155
|
+
@type = type
|
156
|
+
@acceptor = Acceptor.create(acceptor)
|
157
|
+
@default = default
|
158
|
+
@completion = Completion.create(completion, **{})
|
159
|
+
@desc = WrappableString.make(desc)
|
160
|
+
@long_desc = WrappableString.make_array(long_desc)
|
161
|
+
@display_name = display_name || key.to_s.tr("-", "_").gsub(/\W/, "").upcase
|
162
|
+
end
|
162
163
|
end
|
163
164
|
end
|