pub struct ExitPlugin { /* private fields */ }Expand description
Standalone builtin providing only the exit command.
Use this instead of [SystemPlugin][crate::builtin::system::SystemPlugin]
when an application wants exit without also registering help and
version.
§Shutdown callback
Same mechanism as SystemPlugin: the callback runs before the
process exits. The default callback calls std::process::exit(0)
directly.
use dynamic_cli::plugin::ExitPlugin;
let builtin = ExitPlugin::new()
.with_exit_fn(|| {
eprintln!("Goodbye.");
std::process::exit(0);
});§YAML config
commands:
- name: exit
implementation: system_exit
description: "Exit the application"
aliases: ["quit", "q"]
required: false
arguments: []
options: []§Example
use dynamic_cli::plugin::{ExitPlugin, Plugin};
let builtin = ExitPlugin::new();
assert_eq!(builtin.name(), "exit");
let handlers = builtin.handlers();
assert_eq!(handlers.len(), 1);
assert_eq!(handlers[0].0, "system_exit");Implementations§
Source§impl ExitPlugin
impl ExitPlugin
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new ExitPlugin with the default shutdown behaviour.
§Example
use dynamic_cli::plugin::{ExitPlugin, Plugin};
let builtin = ExitPlugin::new();
assert_eq!(builtin.name(), "exit");Sourcepub fn with_exit_fn<F>(self, f: F) -> Self
pub fn with_exit_fn<F>(self, f: F) -> Self
Supply a custom shutdown callback for system_exit.
The callback must be Fn() + Send + Sync + 'static.
§Example
use dynamic_cli::plugin::ExitPlugin;
let builtin = ExitPlugin::new()
.with_exit_fn(|| {
eprintln!("Saving session…");
std::process::exit(0);
});Trait Implementations§
Source§impl Default for ExitPlugin
impl Default for ExitPlugin
Source§impl Plugin for ExitPlugin
impl Plugin for ExitPlugin
Source§fn description(&self) -> &str
fn description(&self) -> &str
Human-readable description of what this plugin provides.
Auto Trait Implementations§
impl !RefUnwindSafe for ExitPlugin
impl !UnwindSafe for ExitPlugin
impl Freeze for ExitPlugin
impl Send for ExitPlugin
impl Sync for ExitPlugin
impl Unpin for ExitPlugin
impl UnsafeUnpin for ExitPlugin
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> 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