Module: Rakit::Shell
- Defined in:
- lib/rakit/shell.rb,
lib/generated/rakit.shell_pb.rb
Defined Under Namespace
Modules: CommandService
Constant Summary collapse
- CHECK =
"\e[32m✓\e[0m"- CROSS =
"\e[31m✗\e[0m"- Command =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("rakit.shell.Command").msgclass
- AcceptanceCriteria =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("rakit.shell.AcceptanceCriteria").msgclass
- TestResult =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("rakit.shell.TestResult").msgclass
- FormatRequest =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("rakit.shell.FormatRequest").msgclass
- FormatResponse =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("rakit.shell.FormatResponse").msgclass
- CommandFormat =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("rakit.shell.CommandFormat").enummodule
Class Method Summary collapse
-
.run(cmd) ⇒ Object
Run a shell command string.
Class Method Details
.run(cmd) ⇒ Object
Run a shell command string. On Unix uses sh -c; on Windows uses COMSPEC (usually cmd.exe /c) so we do not require a POSIX shell (avoids Errno::ENOENT for sh on plain Windows). Prints ✓ (green) + cmd on success, or ✗ (red) + cmd then stdout/stderr on failure. Returns the Command with result fields set.
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/rakit/shell.rb', line 192 def self.run(cmd) command = if ::Gem.win_platform? exe = ENV["COMSPEC"].to_s.strip exe = "cmd.exe" if exe.empty? Command.new(name: exe, args: ["/c", cmd.to_s], working_directory: "") else Command.new(name: "sh", args: ["-c", cmd.to_s], working_directory: "") end result = CommandService.execute(command) if result.exit_status == 0 puts "#{CHECK} #{cmd}" else puts "#{CROSS} #{cmd}" puts "stdout:\n#{result.stdout}" if result.stdout && !result.stdout.empty? puts "stderr:\n#{result.stderr}" if result.stderr && !result.stderr.empty? end result end |