Cling

Struct Cling 

Source
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>

Source

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.

Source

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

Source

pub fn new(parsed: T) -> Cling<T, Ready>

Create a Cling application from a parsed clap struct.

Source

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.

Source

pub fn parse() -> Cling<T, Ready>

Parse command line arguments and exit if parsing failed.

Source

pub fn try_parse() -> Result<Cling<T, Ready>, CliError>

Attempt to parse command line arguments and return a runnable Cling application.

Source

pub fn try_parse_from<I, B>(itr: I) -> Result<Cling<T, Ready>, CliError>
where I: IntoIterator<Item = B>, B: Into<OsString> + Clone,

Source

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.

Source

pub fn try_parse_str_with_bin_name( bin_name: &str, input: &str, ) -> Result<Cling<T, Ready>, CliError>

Source

pub fn parse_or_exit() -> Cling<T, Ready>

Parse command line arguments and aborts the program if parsing failed.

Source

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.

Source

pub async fn run_and_exit(self) -> !

Source

pub async fn run_with_state_and_exit<S>(self, state: S) -> !
where S: Clone + Send + Sync + 'static,

Source

pub async fn run(self) -> ClingFinished<T>

Runs the app with a given state.

Source

pub async fn run_with_state<S>(self, state: S) -> ClingFinished<T>
where S: Clone + Send + Sync + 'static,

Source§

impl<T: Run + Parser> Cling<T, Finished>

Cling program has terminated and results can be introspected.

Source

pub fn result_ref(&self) -> &Result<(), CliError>

Source

pub fn result(self) -> Result<(), CliError>

Source

pub fn is_success(&self) -> bool

Source

pub fn is_failure(&self) -> bool

Source

pub fn collected_parameters(&self) -> &CollectedArgs

Source

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>
where S: Send, T: Send,

§

impl<T, S> Sync for Cling<T, S>
where S: Sync, T: Sync,

§

impl<T, S> Unpin for Cling<T, S>
where S: Unpin, T: Unpin,

§

impl<T, S = Build> !UnwindSafe for Cling<T, S>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more