// Copyright (C) 2018 The Duniter Project Developers. // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as // published by the Free Software Foundation, either version 3 of the // License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . //! Define durs-core cli subcommands options. pub mod dbex; pub mod keys; pub mod modules; pub mod reset; pub mod start; use crate::errors::DursCoreError; use crate::DursCore; pub use dbex::*; use durs_conf::DuRsConf; pub use durs_network::cli::sync::SyncOpt; pub use keys::KeysOpt; use log::Level; pub use modules::*; pub use reset::*; pub use start::*; use std::path::PathBuf; /// Durs core options pub struct DursCoreOptions { /// Keypairs file path pub keypairs_file: Option, /// Set log level. pub logs_level: Option, /// Print logs in standard output pub log_stdout: bool, /// Set a custom user profile name pub profile_name: Option, /// Path where user profiles are persisted pub profiles_path: Option, //TODO: add env prefix } /// Durs executable command pub trait DursExecutableCoreCommand { /// Execute Durs command fn execute(self, durs_core: DursCore) -> Result<(), DursCoreError>; } /// Executable module command pub trait ExecutableModuleCommand { /// Execute module command fn execute_module_command(self, options: DursCoreOptions) -> Result<(), DursCoreError>; } /// Durs command with options pub struct DursCommand { /// Durs core options pub options: DursCoreOptions, /// Durs command pub command: DursCommandEnum, } /// Durs command pub enum DursCommandEnum { /// Core command Core(DursCoreCommand), /// Other command Other(T), } impl DursCommand { /// Execute Durs command pub fn execute( self, soft_name: &'static str, soft_version: &'static str, plug_modules: PlugFunc, ) -> Result<(), DursCoreError> where PlugFunc: FnMut(&mut DursCore) -> Result<(), DursCoreError>, { match self.command { DursCommandEnum::Core(core_cmd) => DursCore::execute_core_command( core_cmd, self.options, vec![], plug_modules, soft_name, soft_version, ), DursCommandEnum::Other(cmd) => cmd.execute_module_command(self.options), } } } #[derive(StructOpt, Debug)] /// Core cli subcommands pub enum DursCoreCommand { /// Enable a module EnableOpt(EnableOpt), /// Disable a module DisableOpt(DisableOpt), /// List available modules ListModulesOpt(ListModulesOpt), /// Start node StartOpt(StartOpt), /// Synchronize SyncOpt(SyncOpt), /// Reset data or conf or all ResetOpt(ResetOpt), /// Database explorer DbExOpt(DbExOpt), /// Keys operations KeysOpt(KeysOpt), } /// InvalidInput #[derive(Debug, Copy, Clone)] pub struct InvalidInput(&'static str); impl ToString for InvalidInput { fn to_string(&self) -> String { String::from(self.0) } }