mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 03:27:58 +00:00
Fix purge-chain and print DB info on startup (#5840)
* purge-chain accepts --db option * print DB info on startup * Small refactoring * Added back &self * Add DatabaseParams for PurgeChain, ImportParams and ExportBlocks * Don't force default value * Remove unused fields * Update client/cli/src/commands/export_blocks_cmd.rs * Fix stuff Co-authored-by: Cecile Tonglet <cecile@parity.io> Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::error;
|
||||
use crate::params::{BlockNumber, PruningParams, SharedParams};
|
||||
use crate::params::{BlockNumber, DatabaseParams, PruningParams, SharedParams};
|
||||
use crate::CliConfiguration;
|
||||
use log::info;
|
||||
use sc_service::{
|
||||
@@ -48,7 +48,7 @@ pub struct ExportBlocksCmd {
|
||||
pub to: Option<BlockNumber>,
|
||||
|
||||
/// Use binary output rather than JSON.
|
||||
#[structopt(long = "binary", value_name = "BOOL", parse(try_from_str), default_value("false"))]
|
||||
#[structopt(long)]
|
||||
pub binary: bool,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
@@ -58,6 +58,10 @@ pub struct ExportBlocksCmd {
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
pub pruning_params: PruningParams,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
pub database_params: DatabaseParams,
|
||||
}
|
||||
|
||||
impl ExportBlocksCmd {
|
||||
@@ -103,4 +107,8 @@ impl CliConfiguration for ExportBlocksCmd {
|
||||
fn pruning_params(&self) -> Option<&PruningParams> {
|
||||
Some(&self.pruning_params)
|
||||
}
|
||||
|
||||
fn database_params(&self) -> Option<&DatabaseParams> {
|
||||
Some(&self.database_params)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,6 +150,12 @@ macro_rules! substrate_cli_subcommands {
|
||||
}
|
||||
}
|
||||
|
||||
fn database_params(&self) -> Option<&$crate::DatabaseParams> {
|
||||
match self {
|
||||
$($enum::$variant(cmd) => cmd.database_params()),*
|
||||
}
|
||||
}
|
||||
|
||||
fn base_path(&self) -> $crate::Result<::std::option::Option<::std::path::PathBuf>> {
|
||||
match self {
|
||||
$($enum::$variant(cmd) => cmd.base_path()),*
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::error;
|
||||
use crate::params::SharedParams;
|
||||
use crate::params::{DatabaseParams, SharedParams};
|
||||
use crate::CliConfiguration;
|
||||
use sc_service::{config::DatabaseConfig, Configuration};
|
||||
use sc_service::Configuration;
|
||||
use std::fmt::Debug;
|
||||
use std::fs;
|
||||
use std::io::{self, Write};
|
||||
@@ -33,18 +33,19 @@ pub struct PurgeChainCmd {
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
pub shared_params: SharedParams,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
pub database_params: DatabaseParams,
|
||||
}
|
||||
|
||||
impl PurgeChainCmd {
|
||||
/// Run the purge command
|
||||
pub fn run(&self, config: Configuration) -> error::Result<()> {
|
||||
let db_path = match &config.database {
|
||||
DatabaseConfig::RocksDb { path, .. } => path,
|
||||
_ => {
|
||||
eprintln!("Cannot purge custom database implementation");
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
let db_path = config.database.path()
|
||||
.ok_or_else(||
|
||||
error::Error::Input("Cannot purge custom database implementation".into())
|
||||
)?;
|
||||
|
||||
if !self.yes {
|
||||
print!("Are you sure to remove {:?}? [y/N]: ", &db_path);
|
||||
@@ -81,4 +82,8 @@ impl CliConfiguration for PurgeChainCmd {
|
||||
fn shared_params(&self) -> &SharedParams {
|
||||
&self.shared_params
|
||||
}
|
||||
|
||||
fn database_params(&self) -> Option<&DatabaseParams> {
|
||||
Some(&self.database_params)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user