Sha256: 054679931f56ee205f2c8104fc717a2e1fa5f31c003ece2af9e4f67eb548b205

Contents?: true

Size: 1.65 KB

Versions: 38

Compression:

Stored size: 1.65 KB

Contents

# frozen_string_literal: true

require 'command_line'

# Docs are included here so they can be discovered.

# Run a command and get back the result.
#
# @param command [String] The command to run.
# @param args [Array] Any arguments passed to the command. All arguments will
#   be converted to strings using `to_s`.
# @param [Hash] env: Pass environment variables to use. The key is the name
#   of the environment variable. The value is the value you want that variable
#   to have.
# @param [Integer, Float, nil] Number of seconds to wait for the block to
#   terminate. Floats can be used to specify fractional seconds. A value of 0
#   or nil will execute the block without any timeout.
#
# @yield [stdin] Handle any input on stdin that the command needs.
# @yieldparam stdin [IO]
#
# @example
#   command_line('echo', 'hello')
#
# @example
#   command_line('command_expecting_input') do |stdin|
#     stdin.puts "first input"
#     stdin.puts "second input"
#   end
#
# @example
#   command_line('some_webserver', env: { PORT: '80' })
#
# @return [Result]
def command_line(*args, **kwargs, &block)
  CommandLine.command_line(*args, **kwargs, &block)
end

# Same as CommandLine.command_line except that a failure on exit raises an
# error.
#
# @see CommandLine.command_line
#
# @example
#   command_line!('echo', 'hello')
#
# @example
#   command_line!('grep')
#   # => CommandLine::ExitFailureError (usage: grep ...
#
# @return [Result]
# @raise [CommandLine::ExitFailureError] If the application exits with an
#   error status. The message will be the contents of Result#stderr.
def command_line!(*args, **kwargs, &block)
  CommandLine.command_line!(*args, **kwargs, &block)
end

Version data entries

38 entries across 38 versions & 2 rubygems

Version Path
qiita_org-0.1.35 gems/ruby/2.7.0/gems/command_line-2.0.1/lib/command_line/global.rb
qiita_org-0.1.34 gems/ruby/2.7.0/gems/command_line-2.0.1/lib/command_line/global.rb
qiita_org-0.1.33 gems/ruby/2.7.0/gems/command_line-2.0.1/lib/command_line/global.rb
qiita_org-0.1.32 gems/ruby/2.7.0/gems/command_line-2.0.1/lib/command_line/global.rb
qiita_org-0.1.31 gems/ruby/2.7.0/gems/command_line-2.0.1/lib/command_line/global.rb
qiita_org-0.1.30 gems/ruby/2.7.0/gems/command_line-2.0.1/lib/command_line/global.rb
qiita_org-0.1.29 gems/ruby/2.7.0/gems/command_line-2.0.1/lib/command_line/global.rb
qiita_org-0.1.28 gems/ruby/2.7.0/gems/command_line-2.0.1/lib/command_line/global.rb
qiita_org-0.1.27 gems/ruby/2.7.0/gems/command_line-2.0.1/lib/command_line/global.rb
qiita_org-0.1.26 gems/ruby/2.7.0/gems/command_line-2.0.1/lib/command_line/global.rb
qiita_org-0.1.25 gems/ruby/2.7.0/gems/command_line-2.0.1/lib/command_line/global.rb
qiita_org-0.1.24 gems/ruby/2.7.0/gems/command_line-2.0.1/lib/command_line/global.rb
qiita_org-0.1.23 gems/ruby/2.7.0/gems/command_line-2.0.1/lib/command_line/global.rb
qiita_org-0.1.22 gems/ruby/2.7.0/gems/command_line-2.0.1/lib/command_line/global.rb
qiita_org-0.1.21 gems/ruby/2.7.0/gems/command_line-2.0.1/lib/command_line/global.rb
qiita_org-0.1.20 gems/ruby/2.7.0/gems/command_line-2.0.1/lib/command_line/global.rb
qiita_org-0.1.19 gems/ruby/2.7.0/gems/command_line-2.0.1/lib/command_line/global.rb
qiita_org-0.1.18 gems/ruby/2.7.0/gems/command_line-2.0.1/lib/command_line/global.rb
qiita_org-0.1.17 gems/ruby/2.7.0/gems/command_line-2.0.1/lib/command_line/global.rb
qiita_org-0.1.16 gems/ruby/2.7.0/gems/command_line-2.0.1/lib/command_line/global.rb