Module: Sumi::Function::Shell
- Included in:
- Sumi::Function
- Defined in:
- function/lib/sumi/function/shell.rb
Overview
Defined Under Namespace
Classes: Result
Instance Method Summary collapse
-
#executable(program) ⇒ String?
Returns the absolute path of the first executable regular file, or nil.
-
#executable!(*args) ⇒ nil
Requires the first command argument to name an executable program.
-
#executable?(program) ⇒ Boolean
Checks whether a program exists and is executable.
-
#sh(*args) { ... } ⇒ Sumi::Function::Shell::Result
Runs a command and captures stdout, stderr, and exit status.
-
#sh!(*args) { ... } ⇒ Sumi::Function::Shell::Result
Runs a command, requiring both executable lookup and successful exit status.
Instance Method Details
#executable(program) ⇒ String?
PATH is evaluated on every call. Empty PATH segments mean the current directory.
Returns the absolute path of the first executable regular file, or nil.
16 |
# File 'function/lib/sumi/function/shell.rb', line 16 def executable(program) = find_executable(program, ENV.fetch("PATH", "")) |
#executable!(*args) ⇒ nil
The first argument is checked as one exact argv entry. It is never shell-split.
Requires the first command argument to name an executable program.
29 30 31 32 33 |
# File 'function/lib/sumi/function/shell.rb', line 29 def executable!(*args) env, program, rest = Command.parse(args) ArgumentError.("Shell command required") if env && rest.empty? Error.("Missing executable: #{program}") if rest.empty? || !find_executable(program, command_path(env)) end |
#executable?(program) ⇒ Boolean
Checks whether a program exists and is executable.
22 |
# File 'function/lib/sumi/function/shell.rb', line 22 def executable?(program) = !executable(program).nil? |
#sh(*args) { ... } ⇒ Sumi::Function::Shell::Result
383 |
# File 'function/lib/sumi/function/shell.rb', line 383 def sh(...) = Runner.new.(...) |
#sh!(*args) { ... } ⇒ Sumi::Function::Shell::Result
The child's stdin is closed after the input block. During execution, the first SIGINT sends TERM to the child process and the second SIGINT as KILL to each active child outside trap context, then restores the previous handler.
Runs a command, requiring both executable lookup and successful exit status.
397 398 399 400 401 402 403 404 405 406 407 408 |
# File 'function/lib/sumi/function/shell.rb', line 397 def sh!(*args, &block) executable!(*args) unless args.empty? sh(*args, &block).tap do |result| unless result.ok? warn(result.err) warn("") Error.("Command failed: #{result.cmd}") end end end |