terminal_rb 1.0.6 → 1.0.9

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.
data/lib/terminal.rb CHANGED
@@ -72,28 +72,52 @@ module Terminal
72
72
 
73
73
  # Execute a shell command.
74
74
  #
75
- # @overload sh(*cmd, **options)
76
- # Run a command and capture output.
75
+ # Output lines are collected or yielded without their trailing newline.
76
+ #
77
+ # @overload sh(*cmd, env: {}, shell: false, input: nil, **options)
78
+ # Run a command and capture its output.
79
+ #
80
+ # @example
81
+ # status, output, error = Terminal.sh('echo', 'hello')
82
+ # output # => ["hello"]
83
+ #
77
84
  # @param cmd [Array<String>] command and arguments
78
- # @param options [Hash] options passed to the shell runner
85
+ # @param env [Hash] environment variables for the command
86
+ # @param shell [true, false]
87
+ # when true the `cmd` is executed via the shell,
88
+ # when false, the executable is direct executed
89
+ # (see `Process.spawn` for this)
90
+ # @param input [String, IO, Array<String>, Enumerable, nil]
91
+ # data written to the command's standard input
92
+ # @param options [Hash] passed to `Process.spawn`
93
+ # (`:in`, `:out`, `:err` are ignored)
79
94
  # @return [Array<Process::Status, Array<String>, Array<String>>]
80
95
  # `[status, stdout_lines, stderr_lines]`
96
+ # @return [nil] when the command can not be executed
97
+ #
98
+ # @overload sh(*cmd, env: {}, shell: false, input: nil, **options, &block)
99
+ # Run a command and stream its output to a block.
100
+ #
81
101
  # @example
82
- # status, output, error = Terminal.sh('echo', 'hello')
83
- # output # => ["hello\n"]
102
+ # Terminal.sh('make') do |line, type|
103
+ # Terminal.puts(type == :error ? "[red]#{line}[/]" : line)
104
+ # end
84
105
  #
85
- # @overload sh(*cmd, **options, &block)
86
- # Run a command and stream output to a block.
87
106
  # @param cmd [Array<String>] command and arguments
88
- # @param options [Hash] options passed to the shell runner
107
+ # @param env [Hash] environment variables for the command
108
+ # @param shell [true, false]
109
+ # when true the `cmd` is executed via the shell,
110
+ # when false, the executable is direct executed
111
+ # (see `Process.spawn` for this)
112
+ # @param input [String, IO, Array<String>, Enumerable, nil]
113
+ # data written to the command's standard input
114
+ # @param options [Hash] passed to `Process.spawn`
115
+ # (`:in`, `:out`, `:err` are ignored)
89
116
  # @yield [line, type] called for each output line
90
117
  # @yieldparam line [String] the output line
91
118
  # @yieldparam type [Symbol] `:output` or `:error`
92
119
  # @return [Process::Status] the exit status
93
- # @example
94
- # Terminal.sh('make') do |line, type|
95
- # Terminal.puts(type == :error ? "[red]#{line}[/]" : line)
96
- # end
120
+ # @return [nil] when the command can not be executed
97
121
  #
98
122
  # @raise [ArgumentError] if no command is given
99
123
  def sh(*cmd, **, &)
@@ -101,7 +125,8 @@ module Terminal
101
125
  return Shell.run(*cmd, **, &) if block_given?
102
126
  out = []
103
127
  err = []
104
- [Shell.run(*cmd, **) { |l, t| (t == :error ? err : out) << l }, out, err]
128
+ ret = Shell.run(*cmd, **) { |l, t| (t == :error ? err : out) << l }
129
+ [ret, out, err] if ret
105
130
  end
106
131
 
107
132
  #
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terminal_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Blumtritt
@@ -60,7 +60,7 @@ metadata:
60
60
  yard.run: yard
61
61
  source_code_uri: https://codeberg.org/mblumtritt/Terminal.rb
62
62
  bug_tracker_uri: https://codeberg.org/mblumtritt/Terminal.rb/issues
63
- documentation_uri: https://rubydoc.info/gems/terminal_rb/1.0.6
63
+ documentation_uri: https://rubydoc.info/gems/terminal_rb/1.0.9
64
64
  rdoc_options: []
65
65
  require_paths:
66
66
  - lib
@@ -75,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  - !ruby/object:Gem::Version
76
76
  version: '0'
77
77
  requirements: []
78
- rubygems_version: 4.0.15
78
+ rubygems_version: 4.0.21
79
79
  specification_version: 4
80
80
  summary: Fast terminal access with ANSI, CSIu, mouse events, BBCode, word-wise line
81
81
  break support and much more.