pub trait NativeCommand: Send + Sync {
// Required methods
fn command(&self) -> Command;
fn execute(
&self,
args: &[String],
context: &NativeCommandContext<'_>,
) -> Result<NativeCommandOutcome>;
// Provided methods
fn auth(&self) -> Option<DescribeCommandAuthV1> { ... }
fn describe(&self) -> DescribeCommandV1 { ... }
}Expand description
Trait implemented by in-process commands registered alongside plugins.
Required Methods§
Sourcefn execute(
&self,
args: &[String],
context: &NativeCommandContext<'_>,
) -> Result<NativeCommandOutcome>
fn execute( &self, args: &[String], context: &NativeCommandContext<'_>, ) -> Result<NativeCommandOutcome>
Executes the command using already-parsed argument tokens.
args contains the tokens after the registered command name. For a
command registered as history, the command line osp history clear --all reaches execute as ["clear", "--all"].
The host interprets outcomes as follows:
NativeCommandOutcome::Helpis rendered as a help/guide responseNativeCommandOutcome::Exitterminates the command immediately with that exit codeNativeCommandOutcome::Responseis treated like plugin protocol output and may still flow through trailing DSL stages
Return Err when command execution itself fails. The host formats that
failure like other command errors.
§Examples
use anyhow::Result;
use clap::Command;
use osp_cli::{NativeCommand, NativeCommandContext, NativeCommandOutcome};
struct HistoryCommand;
impl NativeCommand for HistoryCommand {
fn command(&self) -> Command {
Command::new("history").about("Manage local history")
}
fn execute(
&self,
args: &[String],
_context: &NativeCommandContext<'_>,
) -> Result<NativeCommandOutcome> {
match args {
[subcommand, flag] if subcommand == "clear" && flag == "--all" => {
Ok(NativeCommandOutcome::Exit(0))
}
_ => Ok(NativeCommandOutcome::Help(
"usage: history clear --all".to_string(),
)),
}
}
}Provided Methods§
Sourcefn auth(&self) -> Option<DescribeCommandAuthV1>
fn auth(&self) -> Option<DescribeCommandAuthV1>
Returns optional auth/visibility metadata for the command.
Sourcefn describe(&self) -> DescribeCommandV1
fn describe(&self) -> DescribeCommandV1
Builds the plugin-protocol style description for this command.