Skip to main content

PiCliBuilder

Struct PiCliBuilder 

Source
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

Source

pub fn new() -> Self

Source

pub fn mode(self, mode: Mode) -> Self

Source

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.

Source

pub fn model(self, model: impl Into<String>) -> Self

Source

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.

Source

pub fn system_prompt(self, prompt: impl Into<String>) -> Self

Source

pub fn session(self, session: impl Into<String>) -> Self

--session <path|id> — use a specific session file or partial id.

Source

pub fn session_dir(self, dir: impl Into<PathBuf>) -> Self

Source

pub fn session_id(self, id: impl Into<String>) -> Self

--session-id <id> — exact project session id, created if missing.

Source

pub fn fork(self, source: impl Into<String>) -> Self

--fork <path|id> — fork a session into a new one.

Source

pub fn continue_session(self, enabled: bool) -> Self

--continue — continue the previous session.

Source

pub fn no_session(self, enabled: bool) -> Self

--no-session — ephemeral run, nothing persisted.

Source

pub fn name(self, name: impl Into<String>) -> Self

--name — session display name.

Source

pub fn no_tools(self, enabled: bool) -> Self

--no-tools — disable all tools.

Source

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__.

Source

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+).

Source

pub fn thinking(self, level: impl Into<String>) -> Self

--thinking — off, minimal, low, medium, high, xhigh, max.

Source

pub fn print(self, enabled: bool) -> Self

--print — non-interactive: process the prompt and exit.

Source

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.

Source

pub fn no_approve(self, enabled: bool) -> Self

--no-approve — ignore project-local files for this run.

Source

pub fn offline(self, enabled: bool) -> Self

--offline — disable startup network operations.

Source

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+).

Source

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.

Source

pub fn get_working_directory(&self) -> Option<&Path>

The configured working directory, if any.

Source

pub fn extra_args<I, S>(self, args: I) -> Self
where I: IntoIterator<Item = S>, S: Into<OsString>,

Escape hatch: raw args appended after every typed flag, before the positional prompt.

Source

pub fn prompt(self, prompt: impl Into<String>) -> Self

Positional prompt (used with --mode json one-shots).

Source

pub fn assembled_args(&self) -> Vec<OsString>

The full argv (binary not included) — pure and testable.

Trait Implementations§

Source§

impl Clone for PiCliBuilder

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PiCliBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PiCliBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.