wd_run: a project operation management tool
wd_run supports command line parsing and configuration file parsing. It is mainly achieved through the method of registering callbacks.
The following configuration file parsing formats are supported:
Getting Started
[dependencies]
wd_run = "0.2"
Example
use std::future::Future;
use std::pin::Pin;
use wd_run::*;
#[tokio::main]
async fn main() {
ArgsManager::new()
.add_global_flag("name", "wd_run_test", "server name")
.register_init(init_one)
.register_init(init_two)
.register_cmd(
CmdInfo::new("run", "run appliation").add("cycle", 5, "cycle index"),
cmd_run,
)
.register_cmd(
CmdInfo::new("show", "show init value").add("desc", "show info", "none"),
cmd_show,
)
.register_exit(exit)
.run()
.await;
}
pub fn init_one(ctx: Context) -> Pin<Box<dyn Future<Output = Context> + Send>> {
Box::pin(async move {
ctx.set("init_one", "success".to_string()).await;
return ctx;
})
}
pub fn init_two(ctx: Context) -> Pin<Box<dyn Future<Output = Context> + Send>> {
Box::pin(async move {
ctx.set("init_two", "success".to_string()).await;
return ctx;
})
}
pub fn cmd_run(ctx: Context) -> Pin<Box<dyn Future<Output = Context> + Send>> {
Box::pin(async move {
let cycle = parse_args::<_, u32>(&ctx, "cycle").await.unwrap();
for i in 0..cycle {
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
println!("--->{}", i);
}
return ctx;
})
}
pub fn cmd_show(ctx: Context) -> Pin<Box<dyn Future<Output = Context> + Send>> {
Box::pin(async move {
let name = ctx.copy::<_, String>("name").await.unwrap();
let desc = ctx.copy::<_, String>("desc").await.unwrap();
println!("----------> {}:{} <---------------", name, desc);
let one = ctx.copy::<_, String>("init_one").await.unwrap();
let two = ctx.copy::<_, String>("init_two").await.unwrap();
println!("init one:{} two:{}", one, two);
return ctx;
})
}
pub fn exit(ctx: Context) -> Pin<Box<dyn Future<Output = Context> + Send>> {
Box::pin(async move {
println!("game over");
return ctx;
})
}
Run the following command:
cargo run -- run --cycle 3
cargo run -- show --name wd_run
License
Licensed under either of
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.