Skip to content
Snippets Groups Projects
Commit 98514aa8 authored by dvermd's avatar dvermd
Browse files

wip: add explicit keypairs dependency for commands

parent 9f9fd066
No related branches found
No related tags found
No related merge requests found
This commit is part of merge request !275. Comments created here will be created in the context of that merge request.
......@@ -21,7 +21,8 @@ use durs_core::commands::modules::{DisableOpt, EnableOpt, ListModulesOpt};
use durs_core::commands::reset::ResetOpt;
use durs_core::commands::start::StartOpt;
use durs_core::commands::{
DursCommand, DursCommandEnum, DursCoreCommand, DursCoreOptions, ExecutableModuleCommand,
CommandNeedKeypairs, DursCommand, DursCommandEnum, DursCoreCommand, DursCoreOptions,
ExecutableModuleCommand,
};
use durs_core::errors::DursCoreError;
use durs_core::DursCore;
......@@ -62,6 +63,8 @@ pub struct DursCliOpt {
profile_name: Option<String>,
}
impl CommandNeedKeypairs for DursCliOpt {}
impl ExecutableModuleCommand for DursCliOpt {
/// Execute command
fn execute_module_command(self, options: DursCoreOptions) -> Result<(), DursCoreError> {
......
......@@ -15,7 +15,7 @@
//! Durs-core cli : dbex subcommands.
use crate::commands::DursExecutableCoreCommand;
use crate::commands::{CommandNeedKeypairs, DursExecutableCoreCommand};
use crate::dbex;
use crate::errors::DursCoreError;
use crate::DursCore;
......@@ -34,6 +34,8 @@ pub struct DbExOpt {
pub subcommand: DbExSubCommand,
}
impl CommandNeedKeypairs for DbExOpt {}
#[derive(StructOpt, Debug, Clone)]
/// dbex subcommands
pub enum DbExSubCommand {
......
......@@ -15,7 +15,7 @@
//! Durs-core cli : keys subcommands.
use crate::commands::DursExecutableCoreCommand;
use crate::commands::{CommandNeedKeypairs, DursExecutableCoreCommand};
use crate::errors::DursCoreError;
use crate::DursCore;
use clap::arg_enum;
......@@ -36,6 +36,12 @@ pub struct KeysOpt {
pub subcommand: KeysSubCommand,
}
impl CommandNeedKeypairs for KeysOpt {
fn needs_keypairs(&self) -> bool {
true
}
}
#[derive(StructOpt, Debug, Clone, Copy)]
/// keys subcommands
pub enum KeysSubCommand {
......
......@@ -70,11 +70,19 @@ pub trait DursExecutableCoreCommand {
}
/// Executable module command
pub trait ExecutableModuleCommand {
pub trait ExecutableModuleCommand: CommandNeedKeypairs {
/// Execute module command
fn execute_module_command(self, options: DursCoreOptions) -> Result<(), DursCoreError>;
}
/// Do this command use the keypairs
pub trait CommandNeedKeypairs {
/// Do this command use the keypairs
fn needs_keypairs(&self) -> bool {
false
}
}
/// Dunitrust command with options
pub struct DursCommand<T: ExecutableModuleCommand> {
/// Dunitrust core options
......@@ -149,6 +157,22 @@ pub enum DursCoreCommand {
KeysOpt(KeysOpt),
}
impl CommandNeedKeypairs for DursCoreCommand {
/// Do this command use the keypairs
fn needs_keypairs(&self) -> bool {
match self {
DursCoreCommand::EnableOpt(opt) => opt.needs_keypairs(),
DursCoreCommand::DisableOpt(opt) => opt.needs_keypairs(),
DursCoreCommand::ListModulesOpt(opt) => opt.needs_keypairs(),
DursCoreCommand::StartOpt(opt) => opt.needs_keypairs(),
DursCoreCommand::SyncOpt(opt) => opt.needs_keypairs(),
DursCoreCommand::ResetOpt(opt) => opt.needs_keypairs(),
DursCoreCommand::DbExOpt(opt) => opt.needs_keypairs(),
DursCoreCommand::KeysOpt(opt) => opt.needs_keypairs(),
}
}
}
/// InvalidInput
#[derive(Debug, Copy, Clone)]
pub struct InvalidInput(&'static str);
......
......@@ -15,7 +15,7 @@
//! Durs-core cli : modules manager subcommands.
use crate::commands::DursExecutableCoreCommand;
use crate::commands::{CommandNeedKeypairs, DursExecutableCoreCommand};
use crate::errors::DursCoreError;
use crate::DursCore;
use durs_conf::{ChangeGlobalConf, DuRsConf};
......@@ -31,6 +31,8 @@ pub struct EnableOpt {
pub module_name: ModuleName,
}
impl CommandNeedKeypairs for EnableOpt {}
impl DursExecutableCoreCommand for EnableOpt {
#[inline]
fn execute(self, mut durs_core: DursCore<DuRsConf>) -> Result<(), DursCoreError> {
......@@ -51,6 +53,8 @@ pub struct DisableOpt {
pub module_name: ModuleName,
}
impl CommandNeedKeypairs for DisableOpt {}
impl DursExecutableCoreCommand for DisableOpt {
#[inline]
fn execute(self, mut durs_core: DursCore<DuRsConf>) -> Result<(), DursCoreError> {
......@@ -99,3 +103,5 @@ impl ListModulesOpt {
filters
}
}
impl CommandNeedKeypairs for ListModulesOpt {}
......@@ -16,7 +16,7 @@
//! Durs-core cli : reset subcommand.
use super::InvalidInput;
use crate::commands::DursExecutableCoreCommand;
use crate::commands::{CommandNeedKeypairs, DursExecutableCoreCommand};
use crate::errors::DursCoreError;
use crate::DursCore;
use durs_conf::DuRsConf;
......@@ -54,6 +54,15 @@ pub struct ResetOpt {
pub reset_type: ResetType,
}
impl CommandNeedKeypairs for ResetOpt {
fn needs_keypairs(&self) -> bool {
match self.reset_type {
ResetType::All | ResetType::Conf => true,
ResetType::Datas => false,
}
}
}
impl DursExecutableCoreCommand for ResetOpt {
fn execute(self, durs_core: DursCore<DuRsConf>) -> Result<(), DursCoreError> {
let profile_path = durs_core.soft_meta_datas.profile_path;
......
......@@ -15,7 +15,15 @@
//! Durs-core cli : start subcommands.
use crate::commands::CommandNeedKeypairs;
#[derive(StructOpt, Debug, Copy, Clone)]
#[structopt(name = "start", setting(structopt::clap::AppSettings::ColoredHelp))]
/// start durs server
pub struct StartOpt {}
impl CommandNeedKeypairs for StartOpt {
fn needs_keypairs(&self) -> bool {
true
}
}
......@@ -47,3 +47,10 @@ pub struct SyncOpt {
#[structopt(short = "u", long = "unsafe", hidden = true)]
pub unsafe_mode: bool,
}
impl SyncOpt {
/// Do this command use the keypairs
pub fn needs_keypairs(&self) -> bool {
true
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment