Module: Sevgi::Function::Shell
- Included in:
- Sevgi::Function
- Defined in:
- lib/sevgi/function/shell.rb
Overview
Shell execution helpers and executable lookup utilities.
Defined Under Namespace
Instance Method Summary collapse
-
#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) { ... } ⇒ Sevgi::Function::Shell::Result
Runs a command and captures stdout, stderr, and exit status.
-
#sh!(*args) { ... } ⇒ Sevgi::Function::Shell::Result
Runs a command, requiring both executable lookup and successful exit status.
Instance Method Details
#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.
28 29 30 31 |
# File 'lib/sevgi/function/shell.rb', line 28 def executable!(*args) program = args.first.to_s Error.("Missing executable: #{program}") unless executable?(program) end |
#executable?(program) ⇒ Boolean
PATH is evaluated on every call; empty PATH segments mean the current directory.
Checks whether a program exists and is executable.
13 14 15 16 17 18 19 20 21 |
# File 'lib/sevgi/function/shell.rb', line 13 def executable?(program) program = program.to_s return false if program.empty? return executable_file?(program) if slash_path?(program) ENV.fetch("PATH", "").split(::File::PATH_SEPARATOR, -1).any? do |dir| executable_file?(::File.join(dir.empty? ? "." : dir, program)) end end |
#sh(*args) { ... } ⇒ Sevgi::Function::Shell::Result
300 |
# File 'lib/sevgi/function/shell.rb', line 300 def sh(...) = Runner.new.(...) |
#sh!(*args) { ... } ⇒ Sevgi::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.
313 314 315 316 317 318 319 320 321 322 323 324 |
# File 'lib/sevgi/function/shell.rb', line 313 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 |