Skip to content
Snippets Groups Projects
Select Git revision
  • 6673003528944ff842f0938cb514419585f9a083
  • dev default protected
  • vainamoinen197-transactiondocument-replace-vec-fields-by-smallvec-2
  • dvermd/200-keypairs-dewif
  • elois/wot
  • jawaka/155-dbex-add-dump-fork-tree-command
  • elois/195-bcdbwriteop
  • elois/deps-crypto
  • elois/gva-monetary-mass
  • elois/191-sled
  • elois/195
  • ji_emme/gva-humantimefield
  • 184-gva-rename-commontime-field-to-blockchaintime
  • ji_emme/182-gva-implement-block-meta-data
  • ji_emme/rml14
  • hugo/151-ws2pv2-sync
  • ji_emme/181-gva-implement-identity-request
  • ji_emme/89-implement-client-api-gva-graphql-verification-api
  • logo
  • test-juniper-from-schema
  • elois/exemple-gva-global-context
  • v0.2.0-a4 protected
  • v0.2.0-a2 protected
  • v0.2.0-a protected
  • v0.1.1-a1 protected
  • documents/v0.10.0-b1 protected
  • crypto/v0.4.0-b1 protected
  • crypto/v0.3.0-b3 protected
  • crypto/v0.3.0-b2 protected
  • crypto/v0.3.0-b1 protected
  • wot/v0.8.0-a0.9 protected
  • wot/v0.8.0-a0.8 protected
  • 0.1.0-a0.1 protected
  • v0.0.1-a0.12 protected
  • v0.0.1-a0.11 protected
  • v0.0.1-a0.10 protected
  • v0.0.1-a0.9 protected
  • v0.0.1-a0.8 protected
  • v0.0.1-a0.7 protected
  • v0.0.1-a0.6 protected
  • v0.0.1-a0.5 protected
41 results

mod.rs

Blame
  • mod.rs 3.62 KiB
    //  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 <https://www.gnu.org/licenses/>.
    
    //! 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<PathBuf>,
        /// Set log level.
        pub logs_level: Option<Level>,
        /// Print logs in standard output
        pub log_stdout: bool,
        /// Set a custom user profile name
        pub profile_name: Option<String>,
        /// Path where user profiles are persisted
        pub profiles_path: Option<PathBuf>,
        //TODO: add env prefix
    }
    
    /// Durs executable command
    pub trait DursExecutableCoreCommand {
        /// Execute Durs command
        fn execute(self, durs_core: DursCore<DuRsConf>) -> 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<T: ExecutableModuleCommand> {
        /// Durs core options
        pub options: DursCoreOptions,
        /// Durs command
        pub command: DursCommandEnum<T>,
    }
    
    /// Durs command
    pub enum DursCommandEnum<T: ExecutableModuleCommand> {
        /// Core command
        Core(DursCoreCommand),
        /// Other command
        Other(T),
    }
    
    impl<T: ExecutableModuleCommand> DursCommand<T> {
        /// Execute Durs command
        pub fn execute<PlugFunc>(
            self,
            soft_name: &'static str,
            soft_version: &'static str,
            plug_modules: PlugFunc,
        ) -> Result<(), DursCoreError>
        where
            PlugFunc: FnMut(&mut DursCore<DuRsConf>) -> 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)
        }
    }