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

wd<em>run GitHub Actions wd</em>run on crates.io wd_run on docs.rs License

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] json - [ ] http (coding)

Getting Started

rust [dependencies] wd_run = "0.1"

Example

cmd

Run the following code and the command line bash //help cargo run -- -h //run cargo run -- run ```rust use wdrun::{CmdInfo, KEARGS, ExecManager,Context}; use std::collections::HashMap; use std::sync::Arc;

[tokio::main]

async fn main() { let mut em = ExecManager::new().await; let cr = CoreRun{}; em.registered(cr.clone(), CoreRun::getflagdefault()); em.registered(cr, CoreRun::getflagexit()); em.run().await.unwrap(); }

[derive(Clone)]

pub struct CoreRun { } impl CoreRun { //获取命令行参数参数设置 pub fn getflagdefault() -> CmdInfo { let mut ci = CmdInfo::new("run", "", "start run core"); ci.setflag("-c", "./src/util/conf/config.toml", "config file path"); ci } pub fn getflags(ctx: Arc) -> HashMap { match ctx.getvalue::<&str, HashMap>(&KEARGS) { Some(s) => s, None => HashMap::new(), } } pub fn getflagexit() -> CmdInfo { CmdInfo::new("exit", "", "automatically when exiting the service") } async fn run(&self, ctx: Arc) { //解析输入参数,获取配置文件路径 let flags = CoreRun::get_flags(ctx); let path = flags.get("-c").expect("未获取到配置文件路径").clone(); println!("{}",path); //TODO server do something //... } } //回调事件

[wdrun::eventtrait]

impl wdrun::AsyncEvent for CoreRun { async fn handle(&self, ctx: Arc) { let optcmd = ctx.getmsg::(); if let None = optcmd { return; } let cmd = String::clone(&optcmd.unwrap()); match cmd.asstr() { "run" => { self.run(ctx).await; } "exit" => { println!("-----> stop") // self.stop(); } _ => { println!("Unprocessed commands:{}", cmd) } } } } ```

config

```rust

[derive(Debug,Deserialize)]

pub struct Config { pub log: i32, pub server: String, pub stream: String, }

[test]

fn testconfig () { let conf:Config = wdrun::load_config("./src/util/conf/config.toml").unwrap(); println!("{:?}",conf) } ```

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.