Expand description
Build a Puff program compatible with the CLI.
Use builtin commands or specify your own.
Commands use clap::Command as their specification and return a Runnable that wraps a Future to
run on the Parent’s multi-threaded runtime. To enter into a Puff context in a RunnableCommand, use
the dispatcher to create a Future.
Example
use puff_rs::prelude::*;
use puff_rs::program::clap::{ArgMatches, Command};
use puff_rs::program::{Program, Runnable, RunnableCommand};
use puff_rs::context::PuffContext;
struct MyCommand;
impl RunnableCommand for MyCommand {
fn cli_parser(&self) -> Command {
Command::new("my_custom_command")
}
fn make_runnable(&mut self, args: &ArgMatches, context: PuffContext) -> puff_rs::errors::Result<Runnable> {
// Do some setup like extract args from ArgMatches.
// ...
// Then return a future to run.
Ok(Runnable::new(async {
println!("hello from rust!");
Ok(ExitCode::SUCCESS)
}))
}
}
fn main() -> ExitCode {
Program::new("my_first_program")
.author("Kyle Hanson")
.version("0.0.0")
.command(MyCommand)
.run()
}Run with cargo run my_custom_command or use cargo run help
Re-exports
pub use clap;Modules
Commands to build a program.
Structs
A Puff Program that is responsible for parsing CLI arguments and starting the Runtime.
A wrapper for a boxed future that is able to be run by a Puff Program.
Traits
A Puff command that integrates with the CLI.