pub struct Cling<T, S = Build> { /* private fields */ }Expand description
A Cling program.
Example:
use cling::prelude::*;
#[derive(Run, Parser, Debug, Clone)]
#[cling(run = "run")]
pub struct App {
/// Turn debugging information on
#[arg(short, long, action = ArgAction::Count)]
pub debug: u8,
}
pub async fn run() {
println!("Hello, world!");
}
#[tokio::main]
async fn main() -> ClingFinished<App> {
Cling::parse_and_run().await
}Implementations§
Source§impl<T: Run + Parser> Cling<T, Finished>
impl<T: Run + Parser> Cling<T, Finished>
Sourcepub fn success() -> ClingFinished<T>
pub fn success() -> ClingFinished<T>
Instantiate a successfully finished Cling application. This is useful
when you want to return a successful Cling instance from main()
directly.
Sourcepub fn failed(e: impl Into<CliError>) -> ClingFinished<T>
pub fn failed(e: impl Into<CliError>) -> ClingFinished<T>
Instantiate a failed finished Cling application. This is useful
when you want to wrap an Error into a Cling instance to be returned from
main().
Source§impl<T: Run + Parser> Cling<T, Build>
Parses T with clap and runs until completion
impl<T: Run + Parser> Cling<T, Build>
Parses T with clap and runs until completion
Sourcepub async fn parse_and_run() -> ClingFinished<T>
pub async fn parse_and_run() -> ClingFinished<T>
Parse command line arguments, run the program, and return the finished
Cling application. [ClingFinished<T>] can be returned from main()
directly which will handle printing errors and exiting with the
correct exit code.
Sourcepub fn try_parse() -> Result<Cling<T, Ready>, CliError>
pub fn try_parse() -> Result<Cling<T, Ready>, CliError>
Attempt to parse command line arguments and return a runnable Cling application.
pub fn try_parse_from<I, B>(itr: I) -> Result<Cling<T, Ready>, CliError>
Sourcepub fn try_parse_str(input: &str) -> Result<Cling<T, Ready>, CliError>
pub fn try_parse_str(input: &str) -> Result<Cling<T, Ready>, CliError>
Parses input as a UNIX shell command.
Example input string: sub-command --debug=2. Note that the input
must omit the CLI binary name, otherwise clap parsing will
fail.
pub fn try_parse_str_with_bin_name( bin_name: &str, input: &str, ) -> Result<Cling<T, Ready>, CliError>
Sourcepub fn parse_or_exit() -> Cling<T, Ready>
pub fn parse_or_exit() -> Cling<T, Ready>
Parse command line arguments and aborts the program if parsing failed.
Sourcepub async fn default_run_and_exit() -> !
pub async fn default_run_and_exit() -> !
Parses command line arguments, runs the program and exits afterwards.
Source§impl<T: Run + Parser> Cling<T, Ready>
Cling is now ready to run.
impl<T: Run + Parser> Cling<T, Ready>
Cling is now ready to run.
pub async fn run_and_exit(self) -> !
pub async fn run_with_state_and_exit<S>(self, state: S) -> !
Sourcepub async fn run(self) -> ClingFinished<T>
pub async fn run(self) -> ClingFinished<T>
Runs the app with a given state.
pub async fn run_with_state<S>(self, state: S) -> ClingFinished<T>
Source§impl<T: Run + Parser> Cling<T, Finished>
Cling program has terminated and results can be introspected.
impl<T: Run + Parser> Cling<T, Finished>
Cling program has terminated and results can be introspected.
pub fn result_ref(&self) -> &Result<(), CliError>
pub fn result(self) -> Result<(), CliError>
pub fn is_success(&self) -> bool
pub fn is_failure(&self) -> bool
pub fn collected_parameters(&self) -> &CollectedArgs
pub fn collected_arguments_mut(&mut self) -> &mut CollectedArgs
Auto Trait Implementations§
impl<T, S> Freeze for Cling<T, S>where
T: Freeze,
impl<T, S = Build> !RefUnwindSafe for Cling<T, S>
impl<T, S> Send for Cling<T, S>
impl<T, S> Sync for Cling<T, S>
impl<T, S> Unpin for Cling<T, S>
impl<T, S = Build> !UnwindSafe for Cling<T, S>
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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>
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