import is main subcommand
This commit is contained in:
parent
b482ec54e7
commit
b4719b1bac
11
pbtc/cli.yml
11
pbtc/cli.yml
|
@ -29,9 +29,10 @@ args:
|
|||
- diskdb:
|
||||
long: diskdb
|
||||
help: Use disk storage instead of in-memory one
|
||||
subcommands:
|
||||
- import:
|
||||
long: import
|
||||
value_name: PATH
|
||||
help: Import blocks from bitcoin core database
|
||||
takes_value: true
|
||||
|
||||
about: Import blocks from bitcoin core database
|
||||
args:
|
||||
- PATH:
|
||||
required: true
|
||||
help: Path of the bitcoin core database
|
||||
|
|
|
@ -9,7 +9,6 @@ pub struct Config {
|
|||
pub seednode: Option<String>,
|
||||
pub print_to_console: bool,
|
||||
pub use_disk_database: bool,
|
||||
pub import_path: Option<String>,
|
||||
}
|
||||
|
||||
pub fn parse(matches: &clap::ArgMatches) -> Result<Config, String> {
|
||||
|
@ -40,11 +39,6 @@ pub fn parse(matches: &clap::ArgMatches) -> Result<Config, String> {
|
|||
None => None,
|
||||
};
|
||||
|
||||
let import_path = match matches.value_of("import") {
|
||||
Some(s) => Some(try!(s.parse().map_err(|_| "Invalid import path".to_owned()))),
|
||||
None => None,
|
||||
};
|
||||
|
||||
let config = Config {
|
||||
print_to_console: print_to_console,
|
||||
magic: magic,
|
||||
|
@ -52,7 +46,6 @@ pub fn parse(matches: &clap::ArgMatches) -> Result<Config, String> {
|
|||
connect: connect,
|
||||
seednode: seednode,
|
||||
use_disk_database: use_disk_database,
|
||||
import_path: import_path,
|
||||
};
|
||||
|
||||
Ok(config)
|
||||
|
|
26
pbtc/main.rs
26
pbtc/main.rs
|
@ -54,21 +54,27 @@ fn init_db(db: &Arc<db::Store>) {
|
|||
}
|
||||
}
|
||||
|
||||
fn import_blockchain(db_path: &str) {
|
||||
for (_i, _blk) in import::open_blk_dir(db_path).expect("TODO").enumerate() {
|
||||
// import logic goes here
|
||||
}
|
||||
}
|
||||
|
||||
fn run() -> Result<(), String> {
|
||||
let yaml = load_yaml!("cli.yml");
|
||||
let matches = clap::App::from_yaml(yaml).get_matches();
|
||||
let cfg = try!(config::parse(&matches));
|
||||
|
||||
if let Some(ref import_path) = cfg.import_path {
|
||||
import_blockchain(import_path);
|
||||
return Ok(())
|
||||
match matches.subcommand() {
|
||||
("import", Some(import_matches)) => import_blockchain(import_matches),
|
||||
_ => start_pbtc(&matches),
|
||||
}
|
||||
}
|
||||
|
||||
fn import_blockchain(matches: &clap::ArgMatches) -> Result<(), String> {
|
||||
let db_path = matches.value_of("PATH").expect("PATH is required in cli.yml; qed");
|
||||
let blk_dir = try!(import::open_blk_dir(db_path).map_err(|_| "Import directory does not exist".to_owned()));
|
||||
for (_i, _blk) in blk_dir.enumerate() {
|
||||
// import logic goes here
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn start_pbtc(matches: &clap::ArgMatches) -> Result<(), String> {
|
||||
let cfg = try!(config::parse(matches));
|
||||
|
||||
let mut el = event_loop();
|
||||
|
||||
|
|
Loading…
Reference in New Issue