Skip to content

Commit

Permalink
Replace app builder with derive macros in stress tool (#163)
Browse files Browse the repository at this point in the history
* update cmd tool refer to #155

Signed-off-by: Randy <[email protected]>

* change cmd tool refer to #155

Signed-off-by: Randy <[email protected]>

* update refer #155

Signed-off-by: Randy <[email protected]>

* change cmd tool refer to #155

Signed-off-by: Randy <[email protected]>

* rm useless dependency and change opt paramter type

Signed-off-by: Randy <[email protected]>

* remove useless dependency and change opt paramter type

Signed-off-by: Randy <[email protected]>

* update

Signed-off-by: randy <[email protected]>
  • Loading branch information
ztelur authored Dec 4, 2021
1 parent 90a50b7 commit e87faf7
Show file tree
Hide file tree
Showing 5 changed files with 258 additions and 279 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## File system
.DS_Store
Cargo.lock

## Build
/target
Expand Down
2 changes: 1 addition & 1 deletion ctl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ edition = "2018"
authors = ["The TiKV Authors"]

[dependencies]
structopt = "0.3"
clap = "3.0.0-beta.5"
raft-engine = { path = ".." }
40 changes: 20 additions & 20 deletions ctl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,62 @@

use std::path::Path;

use structopt::StructOpt;
use clap::{crate_authors, crate_version, AppSettings, Parser};

use raft_engine::{Engine, Error, LogQueue, Result};

#[derive(Debug, StructOpt)]
#[structopt[name="basic"]]
#[derive(Debug, Parser)]
#[clap(
name = "basic",
author = crate_authors!(),
version = crate_version!(),
setting = AppSettings::DontCollapseArgsInUsage,
)]
struct ControlOpt {
// sub command type
#[structopt[subcommand]]
#[clap(subcommand)]
cmd: Option<Cmd>,
}

#[derive(Debug, StructOpt)]
#[derive(Debug, Parser)]
pub enum Cmd {
/// dump out all operations in log files
Dump {
#[structopt(
#[clap(
short,
long = "path",
help = "Path of log file directory or specific log file"
about = "Path of log file directory or specific log file"
)]
path: String,

/// raft_group ids(optional), format: raft_groups_id1,raft_group_id2....
#[structopt(short, long, use_delimiter = true)]
#[clap(short, long, use_delimiter = true)]
raft_groups: Vec<u64>,
},

/// check log files for logical errors
Check {
/// Path of directory
#[structopt(short, long)]
#[clap(short, long)]
path: String,
},

/// check log files for logical errors
Truncate {
/// Path of raft-engine storage directory
#[structopt(short, long)]
#[clap(short, long)]
path: String,

/// check mode
#[structopt(short, long, possible_values = &["front", "back", "all"])]
#[clap(short, long, possible_values = &["front", "back", "all"])]
mode: String,

/// queue name
#[structopt(short, long, possible_values = &["append", "rewrite", "all"])]
#[clap(short, long, possible_values = &["append", "rewrite", "all"])]
queue: String,

/// raft_group ids(optional), format: raft_groups_id1,raft_group_id2....
#[structopt(short, long, use_delimiter = true)]
#[clap(short, long, use_delimiter = true)]
raft_groups: Vec<u64>,
},
}
Expand Down Expand Up @@ -85,10 +90,6 @@ impl ControlOpt {
}
}

fn help() {
Self::clap().print_help().ok();
}

fn dump(&self, path: &str, raft_groups: &[u64]) -> Result<()> {
let r = Engine::dump(Path::new(path), &raft_groups.to_vec())?;

Expand Down Expand Up @@ -121,10 +122,9 @@ impl ControlOpt {
}

fn main() {
let opt = ControlOpt::from_args();
let opts: ControlOpt = ControlOpt::parse();

if let Err(e) = opt.validate_and_execute() {
if let Err(e) = opts.validate_and_execute() {
println!("{:?}", e);
ControlOpt::help();
}
}
2 changes: 1 addition & 1 deletion stress/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = ["The TiKV Authors"]
edition = "2018"

[dependencies]
clap = "2.32"
clap = "3.0.0-beta.5"
const_format = "0.2.13"
hdrhistogram = "6.0"
parking_lot_core = "0.8"
Expand Down
Loading

0 comments on commit e87faf7

Please sign in to comment.