Skip to content

Commit

Permalink
feat(cmd): check with each command for status
Browse files Browse the repository at this point in the history
 This commit introduces the following changes:
- It now checks the status of the coffee configuration before executing each command.
- If the coffee status is found to be not sane, the command will return an error.
- To bypass this verification step, you can use the --skip-verify flag.
- By default, the --skip-verify flag is set to true for the httpd, coffee_plugin, and testing crates.

Signed-off-by: Tarek <tareknaser360@gmail.com>
  • Loading branch information
tareknaser authored and vincenzopalazzo committed Oct 12, 2023
1 parent 2711bd6 commit 869d9de
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
14 changes: 12 additions & 2 deletions coffee_cmd/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ pub struct CoffeeArgs {
pub network: Option<String>,
#[clap(short, long, value_parser, name = "data-dir")]
pub data_dir: Option<String>,
#[clap(short, long, action = clap::ArgAction::SetTrue)]
pub skip_verify: bool,
}

/// Coffee subcommand of the command line daemon.
Expand Down Expand Up @@ -59,7 +61,11 @@ pub enum CoffeeCommand {
Search { plugin: String },
/// clean up remote repositories storage information
#[clap(arg_required_else_help = false)]
Nurse {},
Nurse {
/// verify that coffee configuration is sane (without taking any action)
#[arg(short, long, action = clap::ArgAction::SetTrue)]
verify: bool,
},
}

#[derive(Debug, Subcommand)]
Expand Down Expand Up @@ -96,7 +102,7 @@ impl From<&CoffeeCommand> for coffee_core::CoffeeOperation {
CoffeeCommand::Remove { plugin } => Self::Remove(plugin.to_owned()),
CoffeeCommand::Show { plugin } => Self::Show(plugin.to_owned()),
CoffeeCommand::Search { plugin } => Self::Search(plugin.to_owned()),
CoffeeCommand::Nurse {} => Self::Nurse,
CoffeeCommand::Nurse { verify } => Self::Nurse(*verify),
}
}
}
Expand Down Expand Up @@ -127,4 +133,8 @@ impl coffee_core::CoffeeArgs for CoffeeArgs {
fn network(&self) -> Option<String> {
self.network.clone()
}

fn skip_verify(&self) -> bool {
self.skip_verify
}
}
20 changes: 20 additions & 0 deletions coffee_core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use log::info;
use serde::{Deserialize, Serialize};
use std::env;

use crate::CoffeeOperation;
use coffee_lib::utils::check_dir_or_make_if_missing;
use coffee_lib::{errors::CoffeeError, plugin::Plugin};

Expand All @@ -28,6 +29,10 @@ pub struct CoffeeConf {
/// all plugins that are installed
/// with the plugin manager.
pub plugins: Vec<Plugin>,
/// A flag that indicates if the
/// user wants to skip the verification
/// of nurse.
pub skip_verify: bool,
}

impl CoffeeConf {
Expand All @@ -51,6 +56,7 @@ impl CoffeeConf {
plugins: vec![],
cln_config_path: None,
cln_root: None,
skip_verify: false,
};

// check the command line arguments and bind them
Expand Down Expand Up @@ -82,6 +88,20 @@ impl CoffeeConf {
self.config_path = config.to_owned();
}

// If the command is nurse we skip the verification
// because nurse is the command that needs
// to solve the configuration problems.
if !conf.skip_verify() {
match conf.command() {
CoffeeOperation::Nurse(_) => {
self.skip_verify = true;
}
_ => {
self.skip_verify = false;
}
}
}

// FIXME: be able to put the directory also in another place!
// for now it is fixed in the Home/.coffee but another good place
// will be, the .lightning dir
Expand Down
7 changes: 7 additions & 0 deletions coffee_httpd/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,11 @@ impl coffee_core::CoffeeArgs for HttpdArgs {
fn network(&self) -> Option<String> {
self.network.clone()
}

// We don't need to verify the nurse in the httpd
// daemon.
// there is no endpoint for `nurse` in the httpd
fn skip_verify(&self) -> bool {
true
}
}
4 changes: 4 additions & 0 deletions coffee_testing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ impl coffee_core::CoffeeArgs for CoffeeTestingArgs {
fn network(&self) -> Option<String> {
Some(self.network.clone())
}

fn skip_verify(&self) -> bool {
true
}
}

/// Coffee testing manager
Expand Down

0 comments on commit 869d9de

Please sign in to comment.