Attribute Macro cmd_lib_macros::export_cmd[][src]

#[export_cmd]

export the function as an command to be run by run_cmd! or run_fun!

#[export_cmd(my_cmd)]
fn foo(args: CmdArgs, _envs: CmdEnvs, io: &mut CmdStdio) -> CmdResult {
    let msg = format!("msg from foo(), args: {:?}\n", args);
    writeln!(io.errbuf, "{}", msg)?;
    writeln!(io.outbuf, "bar")
}

use_custom_cmd!(my_cmd);
run_cmd!(my_cmd)?;
println!("get result: {}", run_fun!(my_cmd)?);

Here we export function foo as my_cmd command.