pub use self::{
finalize::Finalize,
generate_config::{
GenerateConfig, DEFAULT_EXONUM_LISTEN_PORT, MASTER_KEY_FILE_NAME, PRIVATE_CONFIG_FILE_NAME,
PUBLIC_CONFIG_FILE_NAME,
},
generate_template::GenerateTemplate,
maintenance::{Maintenance, MaintenanceAction},
run::{NodeRunConfig, Run},
run_dev::RunDev,
};
mod finalize;
mod generate_config;
mod generate_template;
mod maintenance;
mod run;
mod run_dev;
use anyhow::Error;
use serde_derive::{Deserialize, Serialize};
use structopt::StructOpt;
use std::path::PathBuf;
pub trait ExonumCommand {
fn execute(self) -> Result<StandardResult, Error>;
}
#[derive(StructOpt, Debug, Serialize, Deserialize)]
#[structopt(author, about)]
#[non_exhaustive]
pub enum Command {
#[structopt(name = "generate-template")]
GenerateTemplate(GenerateTemplate),
#[structopt(name = "generate-config")]
GenerateConfig(GenerateConfig),
#[structopt(name = "finalize")]
Finalize(Finalize),
#[structopt(name = "run")]
Run(Run),
#[structopt(name = "run-dev")]
RunDev(RunDev),
#[structopt(name = "maintenance")]
Maintenance(Maintenance),
}
impl Command {
pub fn from_args() -> Self {
<Self as StructOpt>::from_args()
}
}
impl ExonumCommand for Command {
fn execute(self) -> Result<StandardResult, Error> {
match self {
Self::GenerateTemplate(command) => command.execute(),
Self::GenerateConfig(command) => command.execute(),
Self::Finalize(command) => command.execute(),
Self::Run(command) => command.execute(),
Self::RunDev(command) => command.execute(),
Self::Maintenance(command) => command.execute(),
}
}
}
#[derive(Debug)]
#[non_exhaustive]
pub enum StandardResult {
GenerateTemplate {
template_config_path: PathBuf,
},
GenerateConfig {
public_config_path: PathBuf,
private_config_path: PathBuf,
master_key_path: PathBuf,
},
Finalize {
node_config_path: PathBuf,
},
Run(Box<NodeRunConfig>),
Maintenance {
node_config_path: PathBuf,
db_path: PathBuf,
performed_action: MaintenanceAction,
},
}