toys 0.14.7 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -343,17 +343,28 @@ module Toys
343
343
  complete: :file_system,
344
344
  desc: "Paths to the specs to run (defaults to all specs)"
345
345
 
346
- to_run do
347
- gem_requirements = Array(template.gem_version)
348
- gem "rspec", *gem_requirements
346
+ static :libs, template.libs
347
+ static :gem_version, template.gem_version
348
+ static :rspec_options, template.options
349
+
350
+ # @private
351
+ def run # rubocop:disable all
352
+ gem "rspec", *gem_version
349
353
 
350
354
  ::Dir.chdir(context_directory || ::Dir.getwd) do
351
355
  ruby_args = []
352
- libs = Array(template.libs)
353
356
  ruby_args << "-I#{libs.join(::File::PATH_SEPARATOR)}" unless libs.empty?
354
357
  ruby_args << "-w" if warnings
355
- ruby_args << "-"
356
- ruby_args << "--options" << template.options if template.options
358
+
359
+ code = <<~CODE
360
+ gem 'rspec', *#{gem_version.inspect}
361
+ require 'rspec/core'
362
+ ::RSpec::Core::Runner.invoke
363
+ CODE
364
+ ruby_args << "-e" << code
365
+
366
+ ruby_args << "--"
367
+ ruby_args << "--options" << rspec_options if rspec_options
357
368
  ruby_args << "--order" << order if order
358
369
  ruby_args << "--format" << format if format
359
370
  ruby_args << "--out" << out if out
@@ -364,11 +375,7 @@ module Toys
364
375
  ruby_args << "--tag" << tag if tag
365
376
  ruby_args.concat(files)
366
377
 
367
- result = exec_ruby(ruby_args, in: :controller) do |controller|
368
- controller.in.puts("gem 'rspec', *#{gem_requirements.inspect}")
369
- controller.in.puts("require 'rspec/core'")
370
- controller.in.puts("::RSpec::Core::Runner.invoke")
371
- end
378
+ result = exec_ruby(ruby_args)
372
379
  if result.error?
373
380
  logger.error("RSpec failed!")
374
381
  exit(result.exit_code)
@@ -173,25 +173,31 @@ module Toys
173
173
 
174
174
  set_context_directory template.context_directory if template.context_directory
175
175
 
176
+ static :gem_version, template.gem_version
177
+ static :rubocop_options, template.options
178
+ static :fail_on_error, template.fail_on_error
179
+
176
180
  include :gems
177
181
  include :exec
178
182
 
179
183
  bundler_settings = template.bundler_settings
180
184
  include :bundler, **bundler_settings if bundler_settings
181
185
 
182
- to_run do
183
- gem "rubocop", *template.gem_version
186
+ # @private
187
+ def run
188
+ gem "rubocop", *gem_version
184
189
 
185
190
  ::Dir.chdir(context_directory || ::Dir.getwd) do
186
191
  logger.info "Running RuboCop..."
187
- result = exec_ruby([], in: :controller) do |controller|
188
- controller.in.puts("gem 'rubocop', *#{template.gem_version.inspect}")
189
- controller.in.puts("require 'rubocop'")
190
- controller.in.puts("exit(::RuboCop::CLI.new.run(#{template.options.inspect}))")
191
- end
192
+ code = <<~CODE
193
+ gem 'rubocop', *#{gem_version.inspect}
194
+ require 'rubocop'
195
+ exit(::RuboCop::CLI.new.run(#{rubocop_options.inspect}))
196
+ CODE
197
+ result = exec_ruby(["-e", code])
192
198
  if result.error?
193
199
  logger.error "RuboCop failed!"
194
- exit(1) if template.fail_on_error
200
+ exit(1) if fail_on_error
195
201
  end
196
202
  end
197
203
  end
@@ -464,6 +464,23 @@ module Toys
464
464
  static :generate_output, template.generate_output
465
465
  end
466
466
 
467
+ static :gem_version, template.gem_version
468
+ static :template_files, template.files
469
+ static :run_options, template.options.dup
470
+ static :stats_options, template.stats_options.dup
471
+ static :fail_on_undocumented_objects, template.fail_on_undocumented_objects
472
+ static :fail_on_warning, template.fail_on_warning
473
+ static :output_dir, template.output_dir
474
+ static :show_public, template.show_public
475
+ static :show_protected, template.show_protected
476
+ static :show_private, template.show_private
477
+ static :hide_private_tag, template.hide_private_tag
478
+ static :readme, template.readme
479
+ static :markup, template.markup
480
+ static :yard_template, template.template
481
+ static :template_path, template.template_path
482
+ static :yard_format, template.format
483
+
467
484
  include :exec
468
485
  include :terminal
469
486
  include :gems
@@ -471,60 +488,60 @@ module Toys
471
488
  bundler_settings = template.bundler_settings
472
489
  include :bundler, **bundler_settings if bundler_settings
473
490
 
474
- to_run do
475
- gem_requirements = template.gem_version
476
- gem "yard", *gem_requirements
491
+ # @private
492
+ def run # rubocop:disable all
493
+ gem "yard", *gem_version
477
494
 
478
495
  ::Dir.chdir(context_directory || ::Dir.getwd) do
479
496
  files = []
480
- template.files.each do |pattern|
497
+ template_files.each do |pattern|
481
498
  files.concat(::Dir.glob(pattern))
482
499
  end
483
500
  files.uniq!
484
501
 
485
- run_options = template.options.dup
486
- stats_options = template.stats_options.dup
487
- stats_options << "--list-undoc" if template.fail_on_undocumented_objects
488
- run_options << "--fail-on-warning" if template.fail_on_warning
502
+ stats_options << "--list-undoc" if fail_on_undocumented_objects
503
+ run_options << "--fail-on-warning" if fail_on_warning
489
504
  run_options << "--no-output" unless generate_output
490
- run_options << "--output-dir" << template.output_dir if template.output_dir
491
- run_options << "--no-public" unless template.show_public
492
- run_options << "--protected" if template.show_protected
493
- run_options << "--private" if template.show_private
494
- run_options << "--no-private" if template.hide_private_tag
495
- run_options << "-r" << template.readme if template.readme
496
- run_options << "-m" << template.markup if template.markup
497
- run_options << "-t" << template.template if template.template
498
- run_options << "-p" << template.template_path if template.template_path
499
- run_options << "-f" << template.format if template.format
505
+ run_options << "--output-dir" << output_dir if output_dir
506
+ run_options << "--no-public" unless show_public
507
+ run_options << "--protected" if show_protected
508
+ run_options << "--private" if show_private
509
+ run_options << "--no-private" if hide_private_tag
510
+ run_options << "-r" << readme if readme
511
+ run_options << "-m" << markup if markup
512
+ run_options << "-t" << yard_template if yard_template
513
+ run_options << "-p" << template_path if template_path
514
+ run_options << "-f" << yard_format if yard_format
500
515
  unless stats_options.empty?
501
516
  run_options << "--no-stats"
502
517
  stats_options << "--use-cache"
503
518
  end
504
519
  run_options.concat(files)
505
520
 
506
- result = exec_ruby([], in: :controller) do |controller|
507
- controller.in.puts("gem 'yard', *#{gem_requirements.inspect}")
508
- controller.in.puts("require 'yard'")
509
- controller.in.puts("::YARD::CLI::Yardoc.run(*#{run_options.inspect})")
510
- end
521
+ code = <<~CODE
522
+ gem 'yard', *#{gem_version.inspect}
523
+ require 'yard'
524
+ ::YARD::CLI::Yardoc.run(*#{run_options.inspect})
525
+ CODE
526
+ result = exec_ruby(["-e", code])
511
527
  if result.error?
512
528
  puts("Yardoc encountered errors", :red, :bold) unless verbosity.negative?
513
529
  exit(1)
514
530
  end
515
531
  unless stats_options.empty?
516
- result = exec_ruby([], in: :controller, out: :capture) do |controller|
517
- controller.in.puts("gem 'yard', *#{gem_requirements.inspect}")
518
- controller.in.puts("require 'yard'")
519
- controller.in.puts("::YARD::CLI::Stats.run(*#{stats_options.inspect})")
520
- end
532
+ code = <<~CODE
533
+ gem 'yard', *#{gem_version.inspect}
534
+ require 'yard'
535
+ ::YARD::CLI::Stats.run(*#{stats_options.inspect})
536
+ CODE
537
+ result = exec_ruby(["-e", code], out: :capture)
521
538
  puts result.captured_out
522
539
  if result.error?
523
540
  puts("Yardoc encountered errors", :red, :bold) unless verbosity.negative?
524
541
  exit(1)
525
542
  end
526
543
  exit_on_nonzero_status(result)
527
- if template.fail_on_undocumented_objects && result.captured_out =~ /Undocumented\sObjects:/
544
+ if fail_on_undocumented_objects && result.captured_out =~ /Undocumented\sObjects:/
528
545
  unless verbosity.negative?
529
546
  puts("Yardoc encountered undocumented objects", :red, :bold)
530
547
  end
data/lib/toys/testing.rb CHANGED
@@ -53,7 +53,7 @@ module Toys
53
53
  # end
54
54
  # end
55
55
  #
56
- # # You can test the `message` method as follows:
56
+ # # You can test the `message` method in isolation as follows:
57
57
  #
58
58
  # class MyTest < Minitest::Test
59
59
  # include Toys::Testing
data/lib/toys/version.rb CHANGED
@@ -5,5 +5,5 @@ module Toys
5
5
  # Current version of the Toys command line executable.
6
6
  # @return [String]
7
7
  #
8
- VERSION = "0.14.7"
8
+ VERSION = "0.15.0"
9
9
  end
data/lib/toys.rb CHANGED
@@ -8,6 +8,7 @@ require "toys/version"
8
8
  # don't get clobbered in case someone sets up bundler later.
9
9
  unless ::ENV.key?("TOYS_CORE_LIB_PATH")
10
10
  path = ::File.expand_path("../../toys-core-#{::Toys::VERSION}/lib", __dir__)
11
+ path = ::File.expand_path("../../toys-core/lib", __dir__) unless path && ::File.directory?(path)
11
12
  unless path && ::File.directory?(path)
12
13
  require "rubygems"
13
14
  dep = ::Gem::Dependency.new("toys-core", "= #{::Toys::VERSION}")
@@ -30,6 +31,24 @@ require "toys-core"
30
31
  # workflows. It can also be used as a Rake replacement, providing a more
31
32
  # natural command line interface for your project's build tasks.
32
33
  #
34
+ # This set of documentation includes classes from both Toys-Core, the
35
+ # underlying command line framework, and the Toys executable itself. Most of
36
+ # the actual classes you will likely need to look up are from Toys-Core.
37
+ #
38
+ # ## Common starting points
39
+ #
40
+ # * For information on the DSL used to write tools, start with
41
+ # {Toys::DSL::Tool}.
42
+ # * The base class for tool runtime (i.e. that defines the basic methods
43
+ # available to a tool's implementation) is {Toys::Context}.
44
+ # * For information on writing mixins, see {Toys::Mixin}.
45
+ # * For information on writing templates, see {Toys::Template}.
46
+ # * For information on writing acceptors, see {Toys::Acceptor}.
47
+ # * For information on writing custom shell completions, see {Toys::Completion}.
48
+ # * Standard mixins are defined under the {Toys::StandardMixins} module.
49
+ # * Various utilities are defined under {Toys::Utils}. Some of these serve as
50
+ # the implementations of corresponding mixins.
51
+ #
33
52
  module Toys
34
53
  ##
35
54
  # Path to the Toys executable.
@@ -47,6 +66,9 @@ module Toys
47
66
  ##
48
67
  # Namespace for standard template classes.
49
68
  #
69
+ # These templates are provided by Toys and can be expanded by name by passing
70
+ # a symbol to {Toys::DSL::Tool#expand}.
71
+ #
50
72
  module Templates; end
51
73
  end
52
74
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toys
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.7
4
+ version: 0.15.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: 2023-07-19 00:00:00.000000000 Z
11
+ date: 2023-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: toys-core
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.14.7
19
+ version: 0.15.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.14.7
26
+ version: 0.15.0
27
27
  description: Toys is a configurable command line tool. Write commands in Ruby using
28
28
  a simple DSL, and Toys will provide the command line executable and take care of
29
29
  all the details such as argument parsing, online help, and error reporting. Toys
@@ -98,6 +98,7 @@ files:
98
98
  - core-docs/toys/utils/git_cache.rb
99
99
  - core-docs/toys/utils/help_text.rb
100
100
  - core-docs/toys/utils/pager.rb
101
+ - core-docs/toys/utils/standard_ui.rb
101
102
  - core-docs/toys/utils/terminal.rb
102
103
  - core-docs/toys/utils/xdg.rb
103
104
  - core-docs/toys/wrappable_string.rb
@@ -120,10 +121,10 @@ homepage: https://github.com/dazuma/toys
120
121
  licenses:
121
122
  - MIT
122
123
  metadata:
123
- changelog_uri: https://dazuma.github.io/toys/gems/toys/v0.14.7/file.CHANGELOG.html
124
+ changelog_uri: https://dazuma.github.io/toys/gems/toys/v0.15.0/file.CHANGELOG.html
124
125
  source_code_uri: https://github.com/dazuma/toys/tree/main/toys
125
126
  bug_tracker_uri: https://github.com/dazuma/toys/issues
126
- documentation_uri: https://dazuma.github.io/toys/gems/toys/v0.14.7
127
+ documentation_uri: https://dazuma.github.io/toys/gems/toys/v0.15.0
127
128
  post_install_message:
128
129
  rdoc_options: []
129
130
  require_paths:
@@ -139,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
140
  - !ruby/object:Gem::Version
140
141
  version: '0'
141
142
  requirements: []
142
- rubygems_version: 3.1.6
143
+ rubygems_version: 3.4.10
143
144
  signing_key:
144
145
  specification_version: 4
145
146
  summary: A configurable command line tool