toys-core 0.12.2 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +22 -0
  3. data/LICENSE.md +1 -1
  4. data/README.md +4 -1
  5. data/docs/guide.md +1 -1
  6. data/lib/toys/acceptor.rb +10 -1
  7. data/lib/toys/arg_parser.rb +1 -0
  8. data/lib/toys/cli.rb +127 -107
  9. data/lib/toys/compat.rb +54 -3
  10. data/lib/toys/completion.rb +15 -5
  11. data/lib/toys/context.rb +22 -20
  12. data/lib/toys/core.rb +6 -2
  13. data/lib/toys/dsl/base.rb +2 -0
  14. data/lib/toys/dsl/flag.rb +23 -17
  15. data/lib/toys/dsl/flag_group.rb +11 -7
  16. data/lib/toys/dsl/positional_arg.rb +23 -13
  17. data/lib/toys/dsl/tool.rb +10 -6
  18. data/lib/toys/errors.rb +63 -8
  19. data/lib/toys/flag.rb +660 -651
  20. data/lib/toys/flag_group.rb +19 -6
  21. data/lib/toys/input_file.rb +9 -3
  22. data/lib/toys/loader.rb +129 -115
  23. data/lib/toys/middleware.rb +45 -21
  24. data/lib/toys/mixin.rb +8 -6
  25. data/lib/toys/positional_arg.rb +18 -17
  26. data/lib/toys/settings.rb +81 -67
  27. data/lib/toys/source_info.rb +33 -24
  28. data/lib/toys/standard_middleware/add_verbosity_flags.rb +2 -0
  29. data/lib/toys/standard_middleware/apply_config.rb +1 -0
  30. data/lib/toys/standard_middleware/handle_usage_errors.rb +1 -0
  31. data/lib/toys/standard_middleware/set_default_descriptions.rb +1 -0
  32. data/lib/toys/standard_middleware/show_help.rb +2 -0
  33. data/lib/toys/standard_middleware/show_root_version.rb +2 -0
  34. data/lib/toys/standard_mixins/bundler.rb +22 -14
  35. data/lib/toys/standard_mixins/exec.rb +31 -20
  36. data/lib/toys/standard_mixins/fileutils.rb +3 -1
  37. data/lib/toys/standard_mixins/gems.rb +21 -17
  38. data/lib/toys/standard_mixins/git_cache.rb +5 -7
  39. data/lib/toys/standard_mixins/highline.rb +8 -8
  40. data/lib/toys/standard_mixins/terminal.rb +5 -5
  41. data/lib/toys/standard_mixins/xdg.rb +5 -5
  42. data/lib/toys/template.rb +9 -7
  43. data/lib/toys/tool_definition.rb +209 -202
  44. data/lib/toys/utils/completion_engine.rb +7 -2
  45. data/lib/toys/utils/exec.rb +158 -127
  46. data/lib/toys/utils/gems.rb +81 -57
  47. data/lib/toys/utils/git_cache.rb +674 -45
  48. data/lib/toys/utils/help_text.rb +27 -3
  49. data/lib/toys/utils/terminal.rb +10 -2
  50. data/lib/toys/wrappable_string.rb +9 -2
  51. data/lib/toys-core.rb +14 -5
  52. metadata +4 -4
@@ -200,8 +200,13 @@ module Toys
200
200
  .map { |source, subtools| [source&.source_name || "unknown source", subtools] }
201
201
  end
202
202
 
203
- ## @private
203
+ ##
204
+ # @private
205
+ #
204
206
  class UsageStringAssembler
207
+ ##
208
+ # @private
209
+ #
205
210
  def initialize(tool, executable_name, subtools, separate_sources,
206
211
  indent, left_column_width, wrap_width)
207
212
  @tool = tool
@@ -216,6 +221,9 @@ module Toys
216
221
  assemble
217
222
  end
218
223
 
224
+ ##
225
+ # @private
226
+ #
219
227
  attr_reader :result
220
228
 
221
229
  private
@@ -330,8 +338,13 @@ module Toys
330
338
  end
331
339
  end
332
340
 
333
- ## @private
341
+ ##
342
+ # @private
343
+ #
334
344
  class HelpStringAssembler
345
+ ##
346
+ # @private
347
+ #
335
348
  def initialize(tool, executable_name, delegates, subtools, search_term,
336
349
  show_source_path, separate_sources, indent, indent2, wrap_width, styled)
337
350
  require "toys/utils/terminal"
@@ -349,6 +362,9 @@ module Toys
349
362
  assemble
350
363
  end
351
364
 
365
+ ##
366
+ # @private
367
+ #
352
368
  attr_reader :result
353
369
 
354
370
  private
@@ -638,8 +654,13 @@ module Toys
638
654
  end
639
655
  end
640
656
 
641
- ## @private
657
+ ##
658
+ # @private
659
+ #
642
660
  class ListStringAssembler
661
+ ##
662
+ # @private
663
+ #
643
664
  def initialize(tool, subtools, recursive, search_term, separate_sources,
644
665
  indent, wrap_width, styled)
645
666
  require "toys/utils/terminal"
@@ -653,6 +674,9 @@ module Toys
653
674
  assemble(styled)
654
675
  end
655
676
 
677
+ ##
678
+ # @private
679
+ #
656
680
  attr_reader :result
657
681
 
658
682
  private
@@ -120,7 +120,7 @@ module Toys
120
120
  @output = output
121
121
  @styled =
122
122
  if styled.nil?
123
- output.respond_to?(:tty?) && output.tty?
123
+ output.respond_to?(:tty?) && output.tty? && !::ENV["NO_COLOR"]
124
124
  else
125
125
  styled ? true : false
126
126
  end
@@ -431,8 +431,13 @@ module Toys
431
431
  end
432
432
  end
433
433
 
434
- ## @private
434
+ ##
435
+ # @private
436
+ #
435
437
  class SpinDriver
438
+ ##
439
+ # @private
440
+ #
436
441
  def initialize(terminal, frames, style, frame_length)
437
442
  @mutex = ::Monitor.new
438
443
  @terminal = terminal
@@ -446,6 +451,9 @@ module Toys
446
451
  @thread = @terminal.output.tty? ? start_thread : nil
447
452
  end
448
453
 
454
+ ##
455
+ # @private
456
+ #
449
457
  def stop
450
458
  @mutex.synchronize do
451
459
  @stopping = true
@@ -50,14 +50,21 @@ module Toys
50
50
  end
51
51
  alias to_s string
52
52
 
53
- ## @private
53
+ ##
54
+ # Tests two wrappable strings for equality
55
+ # @param other [Object]
56
+ # @return [Boolean]
57
+ #
54
58
  def ==(other)
55
59
  return false unless other.is_a?(WrappableString)
56
60
  other.fragments == fragments
57
61
  end
58
62
  alias eql? ==
59
63
 
60
- ## @private
64
+ ##
65
+ # Returns a hash code for this object
66
+ # @return [Integer]
67
+ #
61
68
  def hash
62
69
  fragments.hash
63
70
  end
data/lib/toys-core.rb CHANGED
@@ -17,16 +17,21 @@ module Toys
17
17
  # Namespace for DSL classes. These classes provide the directives that can be
18
18
  # used in configuration files. Most are defined in {Toys::DSL::Tool}.
19
19
  #
20
- module DSL; end
20
+ module DSL
21
+ end
21
22
 
22
23
  ##
23
24
  # Namespace for standard middleware classes.
24
25
  #
25
26
  module StandardMiddleware
26
- ## @private
27
+ ##
28
+ # @private
29
+ #
27
30
  COMMON_FLAG_GROUP = :__common
28
31
 
29
- ## @private
32
+ ##
33
+ # @private
34
+ #
30
35
  def self.append_common_flag_group(tool)
31
36
  tool.add_flag_group(type: :optional, name: COMMON_FLAG_GROUP,
32
37
  desc: "Common Flags", report_collisions: false)
@@ -37,7 +42,8 @@ module Toys
37
42
  ##
38
43
  # Namespace for standard mixin classes.
39
44
  #
40
- module StandardMixins; end
45
+ module StandardMixins
46
+ end
41
47
 
42
48
  ##
43
49
  # Namespace for common utility classes.
@@ -46,7 +52,8 @@ module Toys
46
52
  # For example, before using {Toys::Utils::Exec}, you must
47
53
  # `require "toys/utils/exec"`.
48
54
  #
49
- module Utils; end
55
+ module Utils
56
+ end
50
57
 
51
58
  class << self
52
59
  ##
@@ -59,7 +66,9 @@ module Toys
59
66
  attr_accessor :executable_path
60
67
  end
61
68
 
69
+ ##
62
70
  # @private
71
+ #
63
72
  CORE_LIB_PATH = __dir__
64
73
  end
65
74
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toys-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.2
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Azuma
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-30 00:00:00.000000000 Z
11
+ date: 2022-02-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Toys-Core is the command line tool framework underlying Toys. It can
14
14
  be used to create command line executables using the Toys DSL and classes.
@@ -76,10 +76,10 @@ homepage: https://github.com/dazuma/toys
76
76
  licenses:
77
77
  - MIT
78
78
  metadata:
79
- changelog_uri: https://dazuma.github.io/toys/gems/toys-core/v0.12.2/file.CHANGELOG.html
79
+ changelog_uri: https://dazuma.github.io/toys/gems/toys-core/v0.13.0/file.CHANGELOG.html
80
80
  source_code_uri: https://github.com/dazuma/toys/tree/main/toys-core
81
81
  bug_tracker_uri: https://github.com/dazuma/toys/issues
82
- documentation_uri: https://dazuma.github.io/toys/gems/toys-core/v0.12.2
82
+ documentation_uri: https://dazuma.github.io/toys/gems/toys-core/v0.13.0
83
83
  post_install_message:
84
84
  rdoc_options: []
85
85
  require_paths: