pub struct CommandEnvironment { /* private fields */ }Implementations§
Source§impl CommandEnvironment
impl CommandEnvironment
pub fn new() -> Self
Sourcepub fn create<F, Fut>(&mut self, name: &str, handler: F) -> Result<(), String>where
F: Fn(CommandContext) -> Fut + Send + Sync + 'static,
Fut: Future<Output = CommandResult> + Send + 'static,
pub fn create<F, Fut>(&mut self, name: &str, handler: F) -> Result<(), String>where
F: Fn(CommandContext) -> Fut + Send + Sync + 'static,
Fut: Future<Output = CommandResult> + Send + 'static,
Register a typed handler after validating the complete command name. Non-string names are rejected by the compiler before registry mutation.
ⓘ
use command_stream::{CommandEnvironment, CommandResult};
let mut environment = CommandEnvironment::new();
environment.create(None, |_| async { CommandResult::success_empty() });ⓘ
use command_stream::{CommandEnvironment, CommandResult};
let mut environment = CommandEnvironment::new();
environment.create(42, |_| async { CommandResult::success_empty() });pub fn list(&self) -> Vec<String>
pub fn unregister(&mut self, name: &str) -> bool
pub fn installed(&self, name: &str) -> Option<&CommandPackage>
pub fn get(&self, name: &str) -> Option<PackageHandler>
pub async fn run(&self, name: &str, context: CommandContext) -> CommandResult
pub fn extend<F>(&mut self, name: &str, middleware: F) -> Result<(), String>
pub fn inherit( &mut self, name: &str, parent: &str, args: Vec<String>, ) -> Result<(), String>
pub fn compose(&mut self, name: &str, names: &[&str]) -> Result<(), String>
Sourcepub fn install(&mut self, package: CommandPackage) -> Result<(), String>
pub fn install(&mut self, package: CommandPackage) -> Result<(), String>
Validate all commands before replacing a package, including when hot reloading.
pub fn install_with_options( &mut self, package: CommandPackage, options: InstallOptions, ) -> Result<(), String>
pub fn uninstall(&mut self, package: &str)
Sourcepub async fn install_file(
&mut self,
path: impl AsRef<Path>,
) -> Result<String, String>
pub async fn install_file( &mut self, path: impl AsRef<Path>, ) -> Result<String, String>
Canonical file identity makes repeated installation idempotent, including symlinks.
Sourcepub async fn install_npm(
&mut self,
specifier: &str,
cwd: impl AsRef<Path>,
install: bool,
) -> Result<String, String>
pub async fn install_npm( &mut self, specifier: &str, cwd: impl AsRef<Path>, install: bool, ) -> Result<String, String>
Resolve an npm package containing command-stream.json. Rust executes
its literal argv commands without evaluating JavaScript. Missing packages
may be installed with npm lifecycle scripts disabled; install = false
requires an existing package. Reload and uninstall use the same lifecycle.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for CommandEnvironment
impl !UnwindSafe for CommandEnvironment
impl Freeze for CommandEnvironment
impl Send for CommandEnvironment
impl Sync for CommandEnvironment
impl Unpin for CommandEnvironment
impl UnsafeUnpin for CommandEnvironment
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more