Skip to content

Commit

Permalink
feat: add verbose flag to upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
royalpinto007 committed Dec 29, 2023
1 parent 4683f4e commit a02900a
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 10 deletions.
11 changes: 9 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,10 @@ 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
12 changes: 10 additions & 2 deletions coffee_cmd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,16 @@ 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,
} => {
let spinner = if !verbose {
Some(term::spinner("Compiling and installing"))
} else {
None
};
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
8 changes: 6 additions & 2 deletions coffee_core/src/coffee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,11 @@ 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 @@ -346,7 +350,7 @@ impl PluginManager for CoffeeManager {
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
5 changes: 4 additions & 1 deletion coffee_lib/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ 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
6 changes: 5 additions & 1 deletion coffee_lib/src/plugin_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ 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 a02900a

Please sign in to comment.