mirror of
https://github.com/jht5945/rust_util.git
synced 2025-12-27 15:40:03 +08:00
feat: add use clap
This commit is contained in:
11
demo/test_clap/Cargo.toml
Normal file
11
demo/test_clap/Cargo.toml
Normal file
@@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "test_clap"
|
||||
version = "0.1.0"
|
||||
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
rust_util = { version = "0.6", path = "../../", features = ["use_clap"] }
|
||||
clap = "2.0"
|
||||
24
demo/test_clap/src/main.rs
Normal file
24
demo/test_clap/src/main.rs
Normal file
@@ -0,0 +1,24 @@
|
||||
use clap::{App, SubCommand, ArgMatches};
|
||||
use rust_util::util_clap::Command;
|
||||
use rust_util::util_clap::CommandError;
|
||||
use rust_util::util_clap::CommandExecutor;
|
||||
|
||||
struct TestCommand{}
|
||||
impl Command for TestCommand {
|
||||
fn name(&self) -> &str { "test" }
|
||||
|
||||
fn subcommand<'a>(&self) -> App<'a, 'a> {
|
||||
SubCommand::with_name(self.name()).about("Test subcommand")
|
||||
}
|
||||
|
||||
fn run(&self, _arg_matches: &ArgMatches, _: &ArgMatches) -> CommandError {
|
||||
println!("hello test!");
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut c = CommandExecutor::new(None);
|
||||
c.add(Box::new(TestCommand{}));
|
||||
c.run().unwrap();
|
||||
}
|
||||
Reference in New Issue
Block a user