Class: Aidp::ShellExecutor

Inherits:
Object
  • Object
show all
Defined in:
lib/aidp/shell_executor.rb

Overview

Shell command executor wrapper for testability

Provides two modes of execution:

  1. run(command) - Captures output silently via backticks
  2. system(*args) - Wraps Kernel.system() with optional output suppression

In tests, set ShellExecutor.suppress_output = true to suppress all system() output without changing any production code behavior.

Examples:

Production usage

executor = Aidp::ShellExecutor.new
executor.system("git", "fetch", "origin")  # Output shown normally

Test setup (in spec_helper.rb)

Aidp::ShellExecutor.suppress_output = true

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.suppress_outputObject

When true, system() calls will have output redirected to /dev/null Default: false (output shown normally)



24
25
26
# File 'lib/aidp/shell_executor.rb', line 24

def suppress_output
  @suppress_output
end

Instance Method Details

#run(command) ⇒ String

Run a command and capture its output

Parameters:

  • command (String)

    The shell command to run

Returns:

  • (String)

    The command's stdout output



32
33
34
# File 'lib/aidp/shell_executor.rb', line 32

def run(command)
  `#{command}`
end

#success?Boolean

Check if the last command succeeded

Returns:

  • (Boolean)

    true if last command exited with status 0



39
40
41
# File 'lib/aidp/shell_executor.rb', line 39

def success?
  $?.success?
end

#system(*args, **opts) ⇒ Boolean?

Run a command via system(), optionally suppressing output

When suppress_output is true, output is redirected to /dev/null unless explicit out:/err: options are provided.

Parameters:

  • args (Array)

    Arguments passed to Kernel.system

  • opts (Hash)

    Options passed to Kernel.system

Returns:

  • (Boolean, nil)

    Same as Kernel.system



51
52
53
54
55
56
# File 'lib/aidp/shell_executor.rb', line 51

def system(*args, **opts)
  if self.class.suppress_output && !opts.key?(:out) && !opts.key?(:err)
    opts = opts.merge(out: File::NULL, err: File::NULL)
  end
  Kernel.system(*args, **opts)
end