Skip to content

Commit

Permalink
feat: verbose to upgrade
Browse files Browse the repository at this point in the history
feat: add verbose flag to upgrade

fix: lint check

feat: upgrade spinner

fix: minor bugs/comments
  • Loading branch information
royalpinto007 committed Dec 30, 2023
1 parent 4683f4e commit 516f620
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 22 deletions.
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
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
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

0 comments on commit 516f620

Please sign in to comment.