poke-your-api 0.4.0 → 0.4.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 54d9c5d820d46a25b19322bf0b8208a79bff75aff71854354a1f755e3ed998f5
4
- data.tar.gz: f343b6aa3e2d9e4c44f5e4a1273d7d3632fbb5799f67c0d56091254c524174a7
3
+ metadata.gz: f9349d971fd268f0c75b1d9409088e4b33491ce5fa95f4fa29a780af02400904
4
+ data.tar.gz: 36e07caa239aef944dbad213412e48f6e7a8acc68b035d3e61ad6d1fd0dea5df
5
5
  SHA512:
6
- metadata.gz: 5f1809cfd27e99c1a1f1742b79f3b405b548ea0d87fe1e1b403b557677c4f60b41beab68d5613271b5891b8b4532e8f961421d6bdb8f958ee2529e8b25bebed8
7
- data.tar.gz: d89ddcce79212dfafe919eceb3106aef349ce15209ce39c10d4424d2c80bf690dede87b5e485b5b96397a07ab81a254515ee72ff39d618a505b644a02cc3fd4f
6
+ metadata.gz: b097dcf106434d01689f31191fd73036c4a7c4c488c5db41acc43db7dac3cb6e8e33fa1dbbd101ad864ee9da020adb978aab9be9d76421c4d0da41f175a4e9dc
7
+ data.tar.gz: 022a899d6bdc476e15148725c65ff5e8eec0698db1b236de74c664fd2b118fba9e9831520af2696dc65bc6e061901c919aaa5f77f79b6e4367190c81b316b1dd
@@ -12,6 +12,7 @@ require 'pastel'
12
12
 
13
13
  require 'tty-command'
14
14
  require 'tty-editor'
15
+ require 'tty-prompt'
15
16
  require 'tty-table'
16
17
 
17
18
  module Poke
@@ -36,7 +37,7 @@ module Poke
36
37
  request = Request.find_by_name(Config.find_request_name_by_alias(name))
37
38
  else
38
39
  choices = Request.all.sort_by(&:position).map(&:name_with_alias)
39
- name = TTY::Prompt.new(interrupt: :exit).select('Select the endpoint', choices, filter: true, quiet: true)
40
+ name = select_request_name(choices, errors)
40
41
  request = Request.find_by_name_with_alias(name)
41
42
  end
42
43
 
@@ -76,8 +77,8 @@ module Poke
76
77
  curl_command
77
78
  )
78
79
  if command.failure?
79
- output << Pastel.new.decorate(command.err, :red)
80
- output << Poke::Paint.farewell
80
+ errors << Pastel.new.decorate(command.err, :red)
81
+ errors << Poke::Paint.farewell
81
82
  return
82
83
  else
83
84
  errors << Pastel.new.decorate(command.err, :green)
@@ -115,6 +116,30 @@ module Poke
115
116
  ]
116
117
  end
117
118
  # rubocop:enable Style/FormatStringToken
119
+
120
+ def select_request_name(choices, errors)
121
+ with_prompt_output_stream(errors) do |prompt_output|
122
+ TTY::Prompt.new(interrupt: :exit, output: prompt_output).select(
123
+ 'Select the endpoint', choices, filter: true, quiet: true
124
+ )
125
+ end
126
+ end
127
+
128
+ def with_prompt_output_stream(errors)
129
+ stream = default_prompt_output_stream(errors)
130
+ return yield(stream) if stream
131
+
132
+ File.open('/dev/tty', 'w') { |tty| yield(tty) }
133
+ rescue Errno::ENOENT, Errno::ENXIO, Errno::EACCES
134
+ yield(errors)
135
+ end
136
+
137
+ def default_prompt_output_stream(errors)
138
+ return errors if errors.respond_to?(:tty?) && errors.tty?
139
+ return $stderr if $stderr.respond_to?(:tty?) && $stderr.tty?
140
+
141
+ nil
142
+ end
118
143
  end
119
144
  end
120
145
  end
data/lib/poke/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Poke
4
- VERSION = '0.4.0'
4
+ VERSION = '0.4.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: poke-your-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Bator
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-04-27 00:00:00.000000000 Z
11
+ date: 2026-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pastel