Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add fmt githook #218

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions coffee_cmd/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ pub enum CoffeeCommand {
},
/// upgrade a single repository.
#[clap(arg_required_else_help = true)]
Upgrade { repo: String },
Upgrade {
repo: String,
#[arg(short, long, action = clap::ArgAction::SetTrue)]
verbose: bool,
},
/// Print the list of plugins installed in cln.
#[clap(arg_required_else_help = false)]
List {},
Expand Down Expand Up @@ -86,7 +90,7 @@ impl From<&CoffeeCommand> for coffee_core::CoffeeOperation {
verbose,
dynamic,
} => Self::Install(plugin.to_owned(), *verbose, *dynamic),
CoffeeCommand::Upgrade { repo } => Self::Upgrade(repo.to_owned()),
CoffeeCommand::Upgrade { repo, verbose } => Self::Upgrade(repo.to_owned(), *verbose),
CoffeeCommand::List {} => Self::List,
CoffeeCommand::Setup { cln_conf } => Self::Setup(cln_conf.to_owned()),
CoffeeCommand::Remote {
Expand Down
4 changes: 2 additions & 2 deletions coffee_cmd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ async fn main() -> Result<(), CoffeeError> {
let remotes = coffee.list().await;
coffee_term::show_list(remotes)
}
CoffeeCommand::Upgrade { repo } => {
match coffee.upgrade(&repo).await {
CoffeeCommand::Upgrade { repo, verbose } => {
match coffee.upgrade(&repo, verbose).await {
Ok(res) => match res.status {
UpgradeStatus::UpToDate => {
term::info!("Remote repository `{}` is already up to date!", res.repo)
Expand Down
5 changes: 2 additions & 3 deletions coffee_core/src/coffee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ impl PluginManager for CoffeeManager {
})
}

async fn upgrade(&mut self, repo: &str) -> Result<CoffeeUpgrade, CoffeeError> {
async fn upgrade(&mut self, repo: &str, verbose: bool) -> Result<CoffeeUpgrade, CoffeeError> {
// TODO: upgrade should now be able to upgrade a single plugin
// without affecting other plugins installed from the same repo
let repository = self
Expand All @@ -345,8 +345,7 @@ impl PluginManager for CoffeeManager {
let status = repository.upgrade(&self.config.plugins).await?;
for plugins in status.plugins_effected.iter() {
self.remove(plugins).await?;
// FIXME: pass the verbose flag to the upgrade command
self.install(plugins, false, false).await?;
self.install(plugins, verbose, false).await?;
}
self.flush().await?;
Ok(status)
Expand Down
4 changes: 2 additions & 2 deletions coffee_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ pub enum CoffeeOperation {
Install(String, bool, bool),
/// List
List,
// Upgrade(name of the repository)
Upgrade(String),
// Upgrade(name of the repository, verbose run)
Upgrade(String, bool),
Remove(String),
/// Remote(name repository, url of the repository)
Remote(Option<RemoteAction>, bool, Option<String>),
Expand Down
2 changes: 1 addition & 1 deletion coffee_lib/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl Plugin {
}

/// upgrade the plugin to a new version.
pub async fn upgrade(&mut self) -> Result<(), CoffeeError> {
pub async fn upgrade(&mut self, verbose: bool) -> Result<(), CoffeeError> {
todo!("not implemented yet")
}

Expand Down
2 changes: 1 addition & 1 deletion coffee_lib/src/plugin_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub trait PluginManager {
async fn list(&mut self) -> Result<CoffeeList, CoffeeError>;

/// upgrade a single or multiple repositories.
async fn upgrade(&mut self, repo: &str) -> Result<CoffeeUpgrade, CoffeeError>;
async fn upgrade(&mut self, repo: &str, verbose: bool) -> Result<CoffeeUpgrade, CoffeeError>;

/// add the remote repository to the plugin manager.
async fn add_remote(&mut self, name: &str, url: &str) -> Result<(), CoffeeError>;
Expand Down
11 changes: 11 additions & 0 deletions contrib/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

# Run make fmt before committing
# Run make fmt
make fmt

# If make fmt fails, prevent the commit
if [ $? -ne 0 ]; then
echo "Error: make fmt failed. Please fix formatting issues before committing."
exit 1
fi