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 verbose flag to upgrade #217

Merged
merged 1 commit into from
Dec 30, 2023
Merged
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)]
royalpinto007 marked this conversation as resolved.
Show resolved Hide resolved
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
37 changes: 24 additions & 13 deletions coffee_cmd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,31 @@ async fn main() -> Result<(), CoffeeError> {
let remotes = coffee.list().await;
coffee_term::show_list(remotes)
}
CoffeeCommand::Upgrade { repo } => {
match coffee.upgrade(&repo).await {
Ok(res) => match res.status {
UpgradeStatus::UpToDate => {
term::info!("Remote repository `{}` is already up to date!", res.repo)
}
UpgradeStatus::Updated => {
term::success!(
"Remote repository `{}` was successfully upgraded!",
res.repo
)
CoffeeCommand::Upgrade { repo, verbose } => {
let spinner = if !verbose {
Some(term::spinner("Upgrading"))
} else {
None
};
match coffee.upgrade(&repo, verbose).await {
Ok(res) => {
spinner.and_then(|splinner| Some(splinner.finish()));
match res.status {
UpgradeStatus::UpToDate => {
term::info!("Remote repository `{}` is already up to date!", res.repo)
}
UpgradeStatus::Updated => {
term::success!(
"Remote repository `{}` was successfully upgraded!",
res.repo
)
}
}
},
Err(err) => return Err(err),
}
Err(err) => {
spinner.and_then(|spinner| Some(spinner.failed()));
return Err(err);
}
}
Ok(())
}
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
royalpinto007 marked this conversation as resolved.
Show resolved Hide resolved
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, _: 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
Loading