========================================

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:
- [x] json
- [x] yaml
- [x] toml
- [ ] http (coding)
Getting Started
rust
[dependencies]
wd_run = "0.2"
Example
```rust
use std::future::Future;
use std::pin::Pin;
use wd_run::*;
[tokio::main]
async fn main() {
ArgsManager::new()
.registerinit(initone)
.registerinit(inittwo)
.registercmd(
CmdInfo::new("run", "run appliation").add("cycle", 5, "cycle index"),
cmdrun,
)
.registercmd(
CmdInfo::new("show", "show init value").add("desc", "show info", "none"),
cmdshow,
)
.register_exit(exit)
.run()
.await;
}
pub fn initone(ctx: Context) -> Pin + Send>> {
Box::pin(async move {
//load config
// let result:Config = loadconfig("./config.yaml").unwrap();
ctx.set("initone", "success".tostring()).await;
return ctx;
})
}
pub fn inittwo(ctx: Context) -> Pin + Send>> {
Box::pin(async move {
ctx.set("inittwo", "success".tostring()).await;
return ctx;
})
}
pub fn cmdrun(ctx: Context) -> Pin + Send>> {
Box::pin(async move {
let cycle = parseargs::<_, u32>(&ctx, "cycle").await.unwrap();
for i in 0..cycle {
tokio::time::sleep(tokio::time::Duration::fromsecs(1)).await;
println!("--->{}", i);
}
return ctx;
})
}
pub fn cmdshow(ctx: Context) -> Pin + Send>> {
Box::pin(async move {
let desc = ctx.copy::<_, String>("desc").await.unwrap();
println!("----------> show:{} <---------------", desc);
let one = ctx.copy::<_, String>("initone").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 + Send>> {
Box::pin(async move {
println!("game over");
return ctx;
})
}
Run the following command:
bash
cargo run -- run --cycle 3
bash
cargo run -- show
```
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or 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.