pub trait CliContext: Send + Sync {
// Required methods
fn repo_path(&self) -> Option<&Path>;
fn operation_id_wire(&self) -> String;
fn should_output_json(&self, repo_config: Option<&Config>) -> bool;
}Expand description
Small projection of Cli that hosted commands rely on.
Defining the surface here lets the hosted-client implementation compile
against the parsed CLI state without depending on cli.
Keep this trait deliberately small. Every new method is a permanent contract with the hosted side; before adding one, ask whether the hosted command should really need that context at all, or whether the caller can compute it and pass a primitive value.
Required Methods§
Sourcefn repo_path(&self) -> Option<&Path>
fn repo_path(&self) -> Option<&Path>
--repo override; None means “use the process’s current
directory.”
Sourcefn operation_id_wire(&self) -> String
fn operation_id_wire(&self) -> String
--op-id override for idempotent hosted calls. Empty string
means the caller did not supply one and the server should not
dedupe.
Sourcefn should_output_json(&self, repo_config: Option<&Config>) -> bool
fn should_output_json(&self, repo_config: Option<&Config>) -> bool
Resolves whether output should be JSON, encapsulating the
precedence between the --json / --output cli flags, the
user’s global config, and (when supplied) the repo’s
output.format config. Hosted commands typically pass
Some(repo.config()) after opening the repo and None
otherwise.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".