#[non_exhaustive]
pub struct Xtask<Subcommand = Subcommand>where
    Subcommand: Subcommand,
{ pub verbosity: Verbosity, pub subcommand: Option<Subcommand>, }
Expand description

Command line interface definition for cargo xtask command.

cargo-xtask(1)

cargo-xtask 
Rust project automation command

USAGE:
    cargo xtask [OPTIONS] [SUBCOMMAND]

OPTIONS:
    -h, --help       Print help information
    -q, --quiet      Less output per occurrence
    -v, --verbose    More output per occurrence

SUBCOMMANDS:
    build                    `cargo build` with options useful for testing and continuous
                                 integration
    clippy                   `cargo clippy` with options useful for tesing and continuous
                                 integration
    dist                     Build the artifacs and create the archive file for distribution
    dist-archive             Create the archive file for distribution
    dist-build               Build all artifacts for distribution
    dist-build-bin           Build the release binaries for distribution
    dist-build-completion    Build the shell completion files for distribution
    dist-build-doc           Build the documentation for distribution
    dist-build-license       Build the license files for distribution
    dist-build-man           Build the man pages for distribution
    dist-build-readme        Build the readme files for distribution
    dist-clean               Remove the artifacts and archives for distribution
    doc                      `cargo doc` with options useful for testing and continuous
                                 integration
    docsrs                   `cargo doc` with docs.rs specific options
    exec                     Run commands on all workspaces in the current directory and
                                 subdirectories
    fmt                      `cargo fmt` with options useful for testing and continuous
                                 integration
    help                     Print this message or the help of the given subcommand(s)
    lint                     Run lint commands at once
    pre-release              Run pre-release checks
    sync-rdme                `cargo sync-rdme` with options useful for testing and continuous
                                 integration
    test                     `cargo test` with options useful for testing and continuous
                                 integration
    tidy                     Fix the package problems
    udeps                    `cargo udeps` with options useful for testing and continuous
                                 integration

Examples

Use the premade entry point function with default configuration (main feature is required):

use cli_xtask::{Result, Xtask};

fn main() -> Result<()> {
    <Xtask>::main()
}

Use the premade entry point function and custom configuration (main feature is required):

use cli_xtask::{config::Config, Result, Xtask};

fn main() -> Result<()> {
    <Xtask>::main_with_config(|| Ok(Config::new()))
}

If you don’t want to use the main feature, write the main function as follows:

use cli_xtask::{clap::Parser, config::Config, error_handler, logger, Result, Xtask};

fn main() -> Result<()> {
    // Parse command line arguments
    let command = <Xtask>::parse();

    // Setup error handler and logger
    error_handler::install()?; // `error-handler` feature is required
    logger::install(command.verbosity.get())?; // `logger` feature is required

    // Run the subcommand specified by the command line arguments
    command.run(&Config::new())?;

    Ok(())
}

If you want to define your own subcommands, declare the type that implements clap::Subcommand and Run, then use Xtask<YourOwnSubcommand> instead of Xtask.

use cli_xtask::{
    clap::{self, Parser},
    config::Config,
    subcommand, Result, Run, Xtask,
};

// Define your own subcommand arguments
#[derive(Debug, clap::Subcommand)]
enum YourOwnSubcommand {
    #[clap(flatten)]
    Predefined(subcommand::Subcommand),
    /// Run foo function.
    Foo,
    /// Run bar function
    Bar,
}

impl Run for YourOwnSubcommand {
    fn run(&self, config: &Config) -> Result<()> {
        match self {
            Self::Predefined(subcommand) => subcommand.run(config)?,
            Self::Foo => println!("foo!"),
            Self::Bar => println!("bar!"),
        }
        Ok(())
    }

    fn into_any(self: Box<Self>) -> Box<dyn std::any::Any> {
        self
    }

    fn as_any(&self) -> &dyn std::any::Any {
        self
    }

    fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
        self
    }
}

fn main() -> Result<()> {
    Xtask::<YourOwnSubcommand>::main()
}

Fields (Non-exhaustive)

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
verbosity: Verbosity

Verbosity level

subcommand: Option<Subcommand>

Subcommand to run

Implementations

Available on crate feature main only.

Entry point for xtask crate.

This function initializes error handler and logger, then runs the subcommand. Default configuration will be passed to subcommand.

Examples
use cli_xtask::{Result, Xtask};

fn main() -> Result<()> {
    <Xtask>::main()
}
Available on crate feature main only.

Entry point for xtask crate.

This function initializes error handler and logger, then runs the subcommand. Generated configuration by config argument will be passed to subcommand.

Examples
use cli_xtask::{config::Config, Result, Xtask};

fn main() -> Result<()> {
    <Xtask>::main_with_config(|| Ok(Config::new()))
}

Runs the subcommand specified by the command line arguments.

Examples
use cli_xtask::{clap::Parser, config::Config, error_handler, logger, Result, Xtask};

fn main() -> Result<()> {
    // Parse command line arguments
    let command = <Xtask>::parse();

    // Setup error handler and logger
    error_handler::install()?; // `error-handler` feature is required
    logger::install(command.verbosity.get())?; // `logger` feature is required

    // Run the subcommand specified by the command line arguments
    command.run(&Config::new())?;

    Ok(())
}

Trait Implementations

Append to Command so it can instantiate Self. Read more
Append to Command so it can update self. Read more
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Deprecated, replaced with CommandFactory::command
Deprecated, replaced with CommandFactory::command_for_update
Build a Command that can instantiate Self. Read more
Build a Command that can update self. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Instantiate Self from ArgMatches, parsing the arguments as needed. Read more
Instantiate Self from ArgMatches, parsing the arguments as needed. Read more
Assign values from ArgMatches to self.
Assign values from ArgMatches to self.
Parse from std::env::args_os(), exit on error
Parse from std::env::args_os(), return Err on error.
Parse from iterator, exit on error
Parse from iterator, return Err on error.
Update from iterator, exit on error
Update from iterator, return Err on error.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

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

Calls U::from(self).

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

Set the foreground color generically Read more
Set the background color generically. Read more
Change the foreground color to black
Change the background color to black
Change the foreground color to red
Change the background color to red
Change the foreground color to green
Change the background color to green
Change the foreground color to yellow
Change the background color to yellow
Change the foreground color to blue
Change the background color to blue
Change the foreground color to magenta
Change the background color to magenta
Change the foreground color to purple
Change the background color to purple
Change the foreground color to cyan
Change the background color to cyan
Change the foreground color to white
Change the background color to white
Change the foreground color to the terminal default
Change the background color to the terminal default
Change the foreground color to bright black
Change the background color to bright black
Change the foreground color to bright red
Change the background color to bright red
Change the foreground color to bright green
Change the background color to bright green
Change the foreground color to bright yellow
Change the background color to bright yellow
Change the foreground color to bright blue
Change the background color to bright blue
Change the foreground color to bright magenta
Change the background color to bright magenta
Change the foreground color to bright purple
Change the background color to bright purple
Change the foreground color to bright cyan
Change the background color to bright cyan
Change the foreground color to bright white
Change the background color to bright white
Make the text bold
Make the text dim
Make the text italicized
Make the text italicized
Make the text blink
Make the text blink (but fast!)
Swap the foreground and background colors
Hide the text
Cross out the text
Set the foreground color at runtime. Only use if you do not know which color will be used at compile-time. If the color is constant, use either OwoColorize::fg or a color-specific method, such as OwoColorize::green, Read more
Set the background color at runtime. Only use if you do not know what color to use at compile-time. If the color is constant, use either OwoColorize::bg or a color-specific method, such as OwoColorize::on_yellow, Read more
Set the foreground color to a specific RGB value.
Set the background color to a specific RGB value.
Sets the foreground color to an RGB value.
Sets the background color to an RGB value.
Apply a runtime-determined style
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more