Class: RubyClaude::Command
- Inherits:
-
Object
- Object
- RubyClaude::Command
- Defined in:
- lib/ruby_claude/command.rb
Overview
Pure translation of a Configuration plus per-call options into the argv array and child-environment overrides for the claude CLI.
Performs no I/O, which makes flag mapping trivial to unit-test. The prompt is intentionally never part of argv — it is written to the child’s stdin by the Runner to avoid ARG_MAX limits and shell-escaping concerns.
Instance Method Summary collapse
-
#build(stream:, resume: nil) ⇒ Array(Array<String>, Hash)
Build the argv array and child-environment overrides.
-
#child_env ⇒ Hash{String => String, nil}
Environment overrides for the child process.
-
#initialize(config) ⇒ Command
constructor
A new instance of Command.
Constructor Details
#initialize(config) ⇒ Command
Returns a new instance of Command.
12 13 14 |
# File 'lib/ruby_claude/command.rb', line 12 def initialize(config) @config = config end |
Instance Method Details
#build(stream:, resume: nil) ⇒ Array(Array<String>, Hash)
Build the argv array and child-environment overrides.
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ruby_claude/command.rb', line 22 def build(stream:, resume: nil) argv = [@config.binary, "-p", "--output-format", stream ? "stream-json" : "json"] argv << "--verbose" if stream add_flag(argv, "--model", @config.model) add_flag(argv, "--append-system-prompt", @config.append_system_prompt) add_list(argv, "--allowedTools", @config.allowed_tools) add_list(argv, "--disallowedTools", @config.disallowed_tools) add_list(argv, "--add-dir", @config.add_dirs) add_flag(argv, "--permission-mode", @config.) add_flag(argv, "--max-turns", @config.max_turns&.to_s) add_flag(argv, "--resume", resume) [argv, child_env] end |
#child_env ⇒ Hash{String => String, nil}
Environment overrides for the child process. In subscription mode, ANTHROPIC_API_KEY is mapped to nil, which tells Open3/spawn to remove it from the inherited environment so the CLI falls back to the logged-in subscription credentials.
42 43 44 45 46 |
# File 'lib/ruby_claude/command.rb', line 42 def child_env return {} unless @config.use_subscription { "ANTHROPIC_API_KEY" => nil } end |