toys-core 0.14.3 → 0.14.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 73e5d0f680fb70c244e6808947e471a201bc69834c15cfaaaeabf33bb17b3a15
4
- data.tar.gz: 05702f110b55db481633b0eb56569a98002eff8aec6cfd49db78388867c9fa1c
3
+ metadata.gz: 8f37d61c7aa836f0cf61b8f16c3276cfb75b8aa0984f95e646ce4b5f0f75b434
4
+ data.tar.gz: 8030abe70c882204c75f0dc2098da59318e9c514bbb1fd1efdffcb28857e2410
5
5
  SHA512:
6
- metadata.gz: b417c3f249b1d4ca13fe0a14a09771a9a172f3cee72e8e158d8a0fcdbcdf853b8f937e1d61b161f1d2ebafbcecb91fdfe0c0b143d3e22f003405697e6c78bc79
7
- data.tar.gz: 1c323e979f9829623dd9c7048af3aaee23a3b692845c7c19e0af68972245b62411b3daf48653beab7378655910e14ffa0859665b25bfedbb054624edf36f3306
6
+ metadata.gz: b3e7f4918dc4ea6ed9b77506b0f298be2268264d3f4468378c4953f805bb7a9715af09d95fa0b0638bc5b9098e1919cee875beb6af549d70d9d4988e37307219
7
+ data.tar.gz: 1d71d7991acbfbc37e65c25f8507da1d6ed2e26798d2dbfd1117606983d647df8e4b8baac2887022374cf6b7a2fa31fa6e40e1085976acf27a19de1d9a495d0a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Release History
2
2
 
3
+ ### v0.14.5 / 2023-03-20
4
+
5
+ * FIXED: Rescue broken pipe errors by default when running a pager
6
+
7
+ ### v0.14.4 / 2023-01-23
8
+
9
+ * FIXED: Fixed missing require when "toys/utils/xdg" or "toys/utils/git_cache" is required without the rest of toys-core
10
+
3
11
  ### v0.14.3 / 2022-12-29
4
12
 
5
13
  * FIXED: Exit with a code -1 if a non-integer exit code is thrown
data/lib/toys/core.rb CHANGED
@@ -9,7 +9,7 @@ module Toys
9
9
  # Current version of Toys core.
10
10
  # @return [String]
11
11
  #
12
- VERSION = "0.14.3"
12
+ VERSION = "0.14.5"
13
13
  end
14
14
 
15
15
  ##
@@ -8,6 +8,10 @@ module Toys
8
8
  # This mixin provides an instance of {Toys::Utils::Pager}, which invokes
9
9
  # an external pager for output.
10
10
  #
11
+ # You can also pass additional keyword arguments to the `include` directive
12
+ # to configure the pager object. These will be passed on to
13
+ # {Toys::Utils::Pager#initialize}.
14
+ #
11
15
  # @example
12
16
  #
13
17
  # include :pager
@@ -44,13 +48,12 @@ module Toys
44
48
  self[KEY].start(&block)
45
49
  end
46
50
 
47
- on_initialize do
51
+ on_initialize do |**opts|
48
52
  require "toys/utils/pager"
49
- exec_service =
50
- if defined?(::Toys::StandardMixins::Exec)
51
- self[::Toys::StandardMixins::Exec::KEY]
52
- end
53
- self[KEY] = Utils::Pager.new(exec_service: exec_service)
53
+ if !opts.key?(:exec_service) && defined?(::Toys::StandardMixins::Exec)
54
+ opts[:exec_service] = self[::Toys::StandardMixins::Exec::KEY]
55
+ end
56
+ self[KEY] = Utils::Pager.new(**opts)
54
57
  end
55
58
  end
56
59
  end
@@ -3,6 +3,7 @@
3
3
  require "digest"
4
4
  require "fileutils"
5
5
  require "json"
6
+ require "toys/compat"
6
7
  require "toys/utils/exec"
7
8
  require "toys/utils/xdg"
8
9
 
@@ -34,12 +34,18 @@ module Toys
34
34
  # executing commands, or `nil` (the default) to use a default.
35
35
  # @param fallback_io [IO] An IO-like object to write to if the pager is
36
36
  # disabled. Defaults to `$stdout`.
37
+ # @param rescue_broken_pipes [boolean] If `true` (the default), broken
38
+ # pipes are silently rescued. This prevents the exception from
39
+ # propagating out if the pager is interrupted. Set this parameter to
40
+ # `false` to disable this behavior.
37
41
  #
38
- def initialize(command: true, exec_service: nil, fallback_io: nil)
42
+ def initialize(command: true, exec_service: nil, fallback_io: nil,
43
+ rescue_broken_pipes: true)
39
44
  @command = command == true ? Pager.default_command : command
40
45
  @command ||= nil
41
46
  @exec_service = exec_service || Pager.default_exec_service
42
47
  @fallback_io = fallback_io || $stdout
48
+ @rescue_broken_pipes = rescue_broken_pipes
43
49
  end
44
50
 
45
51
  ##
@@ -60,7 +66,11 @@ module Toys
60
66
  def start
61
67
  if @command
62
68
  result = @exec_service.exec(@command, in: :controller) do |controller|
63
- yield controller.in if controller.pid
69
+ begin
70
+ yield controller.in if controller.pid
71
+ rescue ::Errno::EPIPE => e
72
+ raise e unless @rescue_broken_pipes
73
+ end
64
74
  end
65
75
  return result.exit_code unless result.failed?
66
76
  end
@@ -100,6 +110,10 @@ module Toys
100
110
  # executing commands, or `nil` (the default) to use a default.
101
111
  # @param fallback_io [IO] An IO-like object to write to if the pager is
102
112
  # disabled. Defaults to `$stdout`.
113
+ # @param rescue_broken_pipes [boolean] If `true` (the default), broken
114
+ # pipes are silently rescued. This prevents the exception from
115
+ # propagating out if the pager is interrupted. Set this parameter to
116
+ # `false` to disable this behavior.
103
117
  # @return [Integer] The exit code of the pager process.
104
118
  #
105
119
  # @example
@@ -107,8 +121,14 @@ module Toys
107
121
  # Toys::Utils::Pager.start do |io|
108
122
  # io.puts "A long string\n"
109
123
  # end
110
- def start(command: true, exec_service: nil, fallback_io: nil, &block)
111
- pager = new(command: command, exec_service: exec_service, fallback_io: fallback_io)
124
+ #
125
+ def start(command: true,
126
+ exec_service: nil,
127
+ fallback_io: nil,
128
+ rescue_broken_pipes: true,
129
+ &block)
130
+ pager = new(command: command, exec_service: exec_service, fallback_io: fallback_io,
131
+ rescue_broken_pipes: rescue_broken_pipes)
112
132
  pager.start(&block)
113
133
  end
114
134
 
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "toys/compat"
4
+
3
5
  module Toys
4
6
  module Utils
5
7
  ##
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.14.3
4
+ version: 0.14.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Azuma
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-29 00:00:00.000000000 Z
11
+ date: 2023-03-20 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.
@@ -78,10 +78,10 @@ homepage: https://github.com/dazuma/toys
78
78
  licenses:
79
79
  - MIT
80
80
  metadata:
81
- changelog_uri: https://dazuma.github.io/toys/gems/toys-core/v0.14.3/file.CHANGELOG.html
81
+ changelog_uri: https://dazuma.github.io/toys/gems/toys-core/v0.14.5/file.CHANGELOG.html
82
82
  source_code_uri: https://github.com/dazuma/toys/tree/main/toys-core
83
83
  bug_tracker_uri: https://github.com/dazuma/toys/issues
84
- documentation_uri: https://dazuma.github.io/toys/gems/toys-core/v0.14.3
84
+ documentation_uri: https://dazuma.github.io/toys/gems/toys-core/v0.14.5
85
85
  post_install_message:
86
86
  rdoc_options: []
87
87
  require_paths: