| Crates.io | cli-starter |
| lib.rs | cli-starter |
| version | 0.1.1 |
| created_at | 2025-06-22 19:29:23.085932+00 |
| updated_at | 2025-06-22 19:31:35.633271+00 |
| description | A CLI application starter template |
| homepage | |
| repository | https://github.com/Execute-Soft/rust-cli-setter |
| max_upload_size | |
| id | 1721869 |
| size | 33,050 |
A comprehensive CLI application starter template built with Rust, featuring subcommands, error handling, logging, and colored output.
clap for powerful argument parsingcolored crateenv_logger and logthiserrorassert_cmd# Clone or navigate to the project directory
cd cli-starter-project
# Build the project
cargo build --release
# Install globally (optional)
cargo install --path .
# Show help
./target/release/cli-starter --help
# Say hello (defaults to "World")
./target/release/cli-starter hello
# Say hello to a specific person
./target/release/cli-starter hello --name "Alice"
# Show version information
./target/release/cli-starter version
# Enable verbose logging
./target/release/cli-starter --verbose hello
# Run in development mode
cargo run
# Run with specific command
cargo run -- hello --name "Bob"
# Run tests
cargo test
# Check code formatting
cargo fmt
# Run clippy linter
cargo clippy
cli-starter-project/
โโโ Cargo.toml # Project dependencies and metadata
โโโ README.md # This file
โโโ src/
โโโ main.rs # Application entry point
โโโ cli.rs # CLI argument definitions
โโโ error.rs # Custom error types
โโโ commands/ # Command implementations
โโโ mod.rs # Command module exports
โโโ hello.rs # Hello command
โโโ version.rs # Version command
Add the command to src/cli.rs:
#[derive(Subcommand)]
pub enum Commands {
// ... existing commands ...
NewCommand {
#[arg(short, long)]
option: String,
},
}
Create the command module in src/commands/new_command.rs:
use colored::*;
use log::info;
use crate::error::AppError;
pub async fn run(option: String) -> Result<(), AppError> {
info!("Running new command with option: {}", option);
println!("{}", "New command executed!".green().bold());
Ok(())
}
Export the module in src/commands/mod.rs:
pub mod new_command;
pub use new_command::*;
Add the command handler in src/main.rs:
match cli.command {
// ... existing matches ...
Some(commands::Commands::NewCommand { option }) => {
new_command::run(option).await?;
}
}
The project includes optional dependencies for configuration management:
serde and serde_json for JSON configuration filestoml for TOML configuration filesTo enable these features, uncomment the relevant dependencies in Cargo.toml.
The project includes integration testing setup:
# Run all tests
cargo test
# Run specific test
cargo test test_hello_command
# Run tests with output
cargo test -- --nocapture
This project is licensed under the MIT License - see the LICENSE file for details.