项目作者: xpepermint

项目描述 :
Command-line application framework.
高级语言: Rust
项目地址: git://github.com/xpepermint/rawcmd-rs.git
创建时间: 2020-04-14T15:33:20Z
项目社区:https://github.com/xpepermint/rawcmd-rs

开源协议:MIT License

下载


Command-line application framework.

Usage

The command line parser will search for the following pattern:

  1. $ myapp <COMMAND> <FLAGS> <PARAMS> -- <TAIL>

A simple command-line application could look something like this:

  1. use rawcmd::{Context, Command, Flag, Intent};
  2. fn main() {
  3. match Command::with_name("foo")
  4. .with_description("Command 1")
  5. .with_flag(
  6. Flag::with_name("flag1")
  7. .with_alias("f1")
  8. .with_description("Flag 1")
  9. )
  10. .with_param(
  11. Param::with_name("param1")
  12. .with_description("Param 1")
  13. )
  14. .with_subcommand(
  15. Command::with_name("bar")
  16. .with_description("Command 1:1")
  17. .with_flag(
  18. Flag::with_name("flag2")
  19. .with_alias("f2")
  20. .with_description("Flag 2")
  21. )
  22. .with_resolver(|_intent, &mut _context| Ok(2))
  23. )
  24. .with_resolver(|_intent, &mut _context| Ok(3))
  25. .with_handler(|_error, _intent, &mut _context| Ok(4))
  26. .run(
  27. &mut Context::default(),
  28. )
  29. {
  30. Ok(code) => {
  31. println!("Success: {:?}", code);
  32. std::process::exit(0);
  33. },
  34. Err(error) => {
  35. println!("Error: {:?}", error);
  36. std::process::exit(1);
  37. },
  38. }
  39. }

You can use your own custom context object as well:

  1. ...
  2. .run<MyContext>(
  3. MyContext::default()
  4. )