Expand description
§𦦠Clawless
clawless is an opinionated, batteries-included framework for building
command-line applications with Rust. It features low-level building blocks and
high-level abstractions that can be used to build stateless CLIs or stateful
TUI applications.
This crate is the facade of the framework. It re-exports clawless-core,
clawless-cli, and clawless-tui, along with the macros from
clawless-derive, so that applications need only a single dependency. The
full documentation and guides are available at clawless.rs.
Β§Usage
The quickest way to create a new project is the scaffolding tool:
cargo install cargo-clawless
cargo clawless new my-cliTo set up a project manually instead, create a new binary crate with
cargo new --bin <name>. Then add clawless as a dependency. Inside the
crate, open src/main.rs and replace the generated contents with the
following snippet:
mod commands;
clawless::main!();Next, create src/commands.rs to set up your commands module:
clawless::commands!();You can now start creating commands for your application. Commands should be
defined in modules under the commands module. For example, create
src/commands/greet.rs:
use clawless::prelude::*;
#[derive(Debug, Args)]
pub struct GreetArgs {
#[arg(short, long)]
name: String,
}
#[command]
pub async fn greet(args: GreetArgs, context: Context) -> CommandResult {
message!("Hello, {}!", args.name);
Ok(())
}Donβt forget to declare the module in src/commands.rs:
mod greet;
clawless::commands!();You can execute the command by calling your command-line application:
cargo run -- greet --name WorldΒ§Organizing Commands
For larger applications, you can organize commands into nested modules. The module hierarchy naturally maps to subcommand groups:
src/
βββ main.rs
βββ commands.rs
βββ commands/
βββ greet.rs
βββ db.rs
βββ db/
βββ migrate.rs
βββ seed.rsWith this structure:
cargo run -- greetruns thegreetcommandcargo run -- db migrateruns thedb::migratecommandcargo run -- db seedruns thedb::seedcommand
Parent modules declare their children, so src/commands/db.rs contains
mod migrate; and mod seed;.
Β§License
Licensed under either of
- Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (http://opensource.org/licenses/MIT)
at your option.
Β§Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
ModulesΒ§
- cancellation
- Cooperative shutdown
- context
- Context for Clawless commands
- event
- Event types for structured command output
- output
- CLI flag configuration and output types
- prelude
- A prelude module to easily import Clawless essentials
- presenter
- Output port for rendering command output
- resolved_
leaf - Resolved subcommand leaf
- runner
- CLI command runner
- tui
- TUI presentation layer re-exports
MacrosΒ§
- artifact
- Writes an artifact value via the
OutputonContext - commands
- Set up the commands module for a Clawless application
- detail
- Writes a supplementary detail via the
OutputonContext - main
- Initialize and run a Clawless application
- message
- Writes an informational message via the
OutputonContext
StructsΒ§
- Error
- The
Errortype, a wrapper around a dynamic error type.
TraitsΒ§
- Error
Context - Provides the
contextmethod forResult.
Type AliasesΒ§
- Command
Result - Result type for Clawless commands
Attribute MacrosΒ§
- application
- Add a TUI application to a Clawless project
- command
- Add a command to a Clawless application