pub struct Repl {
pub bin: &'static str,
pub json: bool,
pub fixed: Vec<&'static str>,
}repl only.Expand description
A read-eval-print loop over stdin for one binary.
Fields§
§bin: &'static strThe binary name, which the prompt and the help carry.
json: boolWhether the session prints JSON, as its --json says.
fixed: Vec<&'static str>The flags the session fixes when it starts, spelled as a line
would (-a, --account): a line setting one is refused naming
it. A binary adds its own, as in --backend.
Implementations§
Source§impl Repl
impl Repl
Sourcepub fn new(bin: &'static str, json: bool) -> Self
pub fn new(bin: &'static str, json: bool) -> Self
Builds the loop of the binary bin, printing JSON when json is
set, as the session’s printer does, and fixing the shared account,
configuration and log flags.
Sourcepub fn run<T: Subcommand, C: ErrorCode>(
&self,
execute: impl FnMut(&mut StdoutPrinter, T) -> Result<()>,
) -> Result<()>
pub fn run<T: Subcommand, C: ErrorCode>( &self, execute: impl FnMut(&mut StdoutPrinter, T) -> Result<()>, ) -> Result<()>
Runs the loop over stdin until EOF, quit or exit.
T is the binary’s command tree, parsed from each line without
the binary name, and C its failure codes. execute runs one
parsed command with the printer of its line, JSON when the session
or the line asks for it; a repl or mcp line never reaches it.
A version T carries (#[command(version)] on the enum) prints
after any command. The loop claims stdin first, and fails only when
stdin or stdout does.