pub struct PiCliBuilder { /* private fields */ }Expand description
Typed argv builder for the pi CLI.
use pi_codes::cli::{Mode, PiCliBuilder};
let args = PiCliBuilder::new()
.mode(Mode::Rpc)
.no_session(true)
.assembled_args();
assert_eq!(args[0], "--mode");Implementations§
Source§impl PiCliBuilder
impl PiCliBuilder
pub fn new() -> Self
pub fn mode(self, mode: Mode) -> Self
Sourcepub fn provider(self, provider: impl Into<String>) -> Self
pub fn provider(self, provider: impl Into<String>) -> Self
Restrict --model lookup to one provider. pi 1.0.0+ rejects
--provider without --model (Error: --provider requires --model,
exit 1), so pair this with model.
pub fn model(self, model: impl Into<String>) -> Self
Sourcepub fn api_key(self, key: impl Into<String>) -> Self
pub fn api_key(self, key: impl Into<String>) -> Self
API key for the provider. Prefer environment variables — argv is visible to other processes; this exists for parity with the CLI.
pub fn system_prompt(self, prompt: impl Into<String>) -> Self
Sourcepub fn session(self, session: impl Into<String>) -> Self
pub fn session(self, session: impl Into<String>) -> Self
--session <path|id> — use a specific session file or partial id.
pub fn session_dir(self, dir: impl Into<PathBuf>) -> Self
Sourcepub fn session_id(self, id: impl Into<String>) -> Self
pub fn session_id(self, id: impl Into<String>) -> Self
--session-id <id> — exact project session id, created if missing.
Sourcepub fn fork(self, source: impl Into<String>) -> Self
pub fn fork(self, source: impl Into<String>) -> Self
--fork <path|id> — fork a session into a new one.
Sourcepub fn continue_session(self, enabled: bool) -> Self
pub fn continue_session(self, enabled: bool) -> Self
--continue — continue the previous session.
Sourcepub fn no_session(self, enabled: bool) -> Self
pub fn no_session(self, enabled: bool) -> Self
--no-session — ephemeral run, nothing persisted.
Sourcepub fn tools(self, tools: impl Into<String>) -> Self
pub fn tools(self, tools: impl Into<String>) -> Self
--tools — comma-separated tool allowlist. Entries are tool names
or patterns where * matches any characters (pi 1.0.4+). MCP tools
are kept unless an entry starts with mcp__. Entries written as
+name / -name add to or remove from the default selection
instead of replacing it (pi 1.1.0+), e.g. "+codemode,-write".
Sourcepub fn exclude_tools(self, tools: impl Into<String>) -> Self
pub fn exclude_tools(self, tools: impl Into<String>) -> Self
--exclude-tools — comma-separated tool denylist of names or *
patterns, MCP tools included (pi 1.0.4+).
Sourcepub fn thinking(self, level: impl Into<String>) -> Self
pub fn thinking(self, level: impl Into<String>) -> Self
--thinking — off, minimal, low, medium, high, xhigh, max.
Sourcepub fn print(self, enabled: bool) -> Self
pub fn print(self, enabled: bool) -> Self
--print — non-interactive: process the prompt and exit.
Sourcepub fn approve(self, enabled: bool) -> Self
pub fn approve(self, enabled: bool) -> Self
--approve — trust project-local files (extensions, AGENTS.md)
for this run. Note pi has NO tool-approval gate: read/bash/edit/
write always run without prompting; this flag is only about
trusting local config.
Sourcepub fn no_approve(self, enabled: bool) -> Self
pub fn no_approve(self, enabled: bool) -> Self
--no-approve — ignore project-local files for this run.
Sourcepub fn no_mcp(self, enabled: bool) -> Self
pub fn no_mcp(self, enabled: bool) -> Self
--no-mcp — disable the built-in MCP support for this run: no
servers connect and there are no MCP tools (pi 1.0.4+).
Sourcepub fn working_directory(self, dir: impl Into<PathBuf>) -> Self
pub fn working_directory(self, dir: impl Into<PathBuf>) -> Self
Working directory for the spawned process (not a pi flag — pi’s
tools operate relative to its cwd). Used by
crate::client_async::PiRpcClient::spawn.
Sourcepub fn get_working_directory(&self) -> Option<&Path>
pub fn get_working_directory(&self) -> Option<&Path>
The configured working directory, if any.
Sourcepub fn extra_args<I, S>(self, args: I) -> Self
pub fn extra_args<I, S>(self, args: I) -> Self
Escape hatch: raw args appended after every typed flag, before the positional prompt.
Sourcepub fn prompt(self, prompt: impl Into<String>) -> Self
pub fn prompt(self, prompt: impl Into<String>) -> Self
Positional prompt (used with --mode json one-shots).
Sourcepub fn assembled_args(&self) -> Vec<OsString>
pub fn assembled_args(&self) -> Vec<OsString>
The full argv (binary not included) — pure and testable.