mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-01 14:47:55 +00:00
add cli for purge chain (#609)
This commit is contained in:
@@ -211,3 +211,17 @@ subcommands:
|
||||
value_name: PATH
|
||||
help: Specify custom base path.
|
||||
takes_value: true
|
||||
- purge-chain:
|
||||
about: Remove the whole chain data.
|
||||
args:
|
||||
- chain:
|
||||
long: chain
|
||||
value_name: CHAIN_SPEC
|
||||
help: Specify the chain specification.
|
||||
takes_value: true
|
||||
- base-path:
|
||||
long: base-path
|
||||
short: d
|
||||
value_name: PATH
|
||||
help: Specify custom base path.
|
||||
takes_value: true
|
||||
|
||||
@@ -65,6 +65,7 @@ use network::NonReservedPeerMode;
|
||||
|
||||
use std::io::{Write, Read, stdin, stdout};
|
||||
use std::iter;
|
||||
use std::fs;
|
||||
use std::fs::File;
|
||||
use std::net::{Ipv4Addr, SocketAddr};
|
||||
use std::path::{Path, PathBuf};
|
||||
@@ -213,6 +214,12 @@ where
|
||||
return Ok(Action::ExecutedInternally);
|
||||
}
|
||||
|
||||
if let Some(matches) = matches.subcommand_matches("purge-chain") {
|
||||
let spec = load_spec(&matches, spec_factory)?;
|
||||
purge_chain::<F>(matches, spec)?;
|
||||
return Ok(Action::ExecutedInternally);
|
||||
}
|
||||
|
||||
let spec = load_spec(&matches, spec_factory)?;
|
||||
let mut config = service::Configuration::default_with_spec(spec);
|
||||
|
||||
@@ -417,6 +424,30 @@ fn revert_chain<F>(matches: &clap::ArgMatches, spec: ChainSpec<FactoryGenesis<F>
|
||||
Ok(service::chain_ops::revert_chain::<F>(config, As::sa(blocks))?)
|
||||
}
|
||||
|
||||
fn purge_chain<F>(matches: &clap::ArgMatches, spec: ChainSpec<FactoryGenesis<F>>) -> error::Result<()>
|
||||
where F: ServiceFactory,
|
||||
{
|
||||
let base_path = base_path(matches);
|
||||
let database_path = db_path(&base_path, spec.id());
|
||||
|
||||
print!("Are you sure to remove {:?}? (y/n)", &database_path);
|
||||
stdout().flush().expect("failed to flush stdout");
|
||||
|
||||
let mut input = String::new();
|
||||
stdin().read_line(&mut input)?;
|
||||
let input = input.trim();
|
||||
|
||||
match input.chars().nth(0) {
|
||||
Some('y') | Some('Y') => {
|
||||
fs::remove_dir_all(&database_path)?;
|
||||
println!("{:?} removed.", &database_path);
|
||||
},
|
||||
_ => println!("Aborted"),
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn parse_address(default: &str, port_param: &str, matches: &clap::ArgMatches) -> Result<SocketAddr, String> {
|
||||
let mut address: SocketAddr = default.parse().ok().ok_or_else(|| format!("Invalid address specified for --{}.", port_param))?;
|
||||
if let Some(port) = matches.value_of(port_param) {
|
||||
|
||||
Reference in New Issue
Block a user