Skip to content

Commit a9a0523

Browse files
royalpinto007vincenzopalazzo
authored andcommitted
feat: verbose to upgrade
feat: add verbose flag to upgrade fix: lint check feat: upgrade spinner fix: minor bugs/comments
1 parent 1a5e441 commit a9a0523

File tree

6 files changed

+36
-22
lines changed

6 files changed

+36
-22
lines changed

coffee_cmd/src/cmd.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ pub enum CoffeeCommand {
3232
},
3333
/// upgrade a single repository.
3434
#[clap(arg_required_else_help = true)]
35-
Upgrade { repo: String },
35+
Upgrade {
36+
repo: String,
37+
#[arg(short, long, action = clap::ArgAction::SetTrue)]
38+
verbose: bool,
39+
},
3640
/// Print the list of plugins installed in cln.
3741
#[clap(arg_required_else_help = false)]
3842
List {},
@@ -86,7 +90,7 @@ impl From<&CoffeeCommand> for coffee_core::CoffeeOperation {
8690
verbose,
8791
dynamic,
8892
} => Self::Install(plugin.to_owned(), *verbose, *dynamic),
89-
CoffeeCommand::Upgrade { repo } => Self::Upgrade(repo.to_owned()),
93+
CoffeeCommand::Upgrade { repo, verbose } => Self::Upgrade(repo.to_owned(), *verbose),
9094
CoffeeCommand::List {} => Self::List,
9195
CoffeeCommand::Setup { cln_conf } => Self::Setup(cln_conf.to_owned()),
9296
CoffeeCommand::Remote {

coffee_cmd/src/main.rs

+24-13
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,31 @@ async fn main() -> Result<(), CoffeeError> {
5757
let remotes = coffee.list().await;
5858
coffee_term::show_list(remotes)
5959
}
60-
CoffeeCommand::Upgrade { repo } => {
61-
match coffee.upgrade(&repo).await {
62-
Ok(res) => match res.status {
63-
UpgradeStatus::UpToDate => {
64-
term::info!("Remote repository `{}` is already up to date!", res.repo)
65-
}
66-
UpgradeStatus::Updated => {
67-
term::success!(
68-
"Remote repository `{}` was successfully upgraded!",
69-
res.repo
70-
)
60+
CoffeeCommand::Upgrade { repo, verbose } => {
61+
let spinner = if !verbose {
62+
Some(term::spinner("Upgrading"))
63+
} else {
64+
None
65+
};
66+
match coffee.upgrade(&repo, verbose).await {
67+
Ok(res) => {
68+
spinner.and_then(|splinner| Some(splinner.finish()));
69+
match res.status {
70+
UpgradeStatus::UpToDate => {
71+
term::info!("Remote repository `{}` is already up to date!", res.repo)
72+
}
73+
UpgradeStatus::Updated => {
74+
term::success!(
75+
"Remote repository `{}` was successfully upgraded!",
76+
res.repo
77+
)
78+
}
7179
}
72-
},
73-
Err(err) => return Err(err),
80+
}
81+
Err(err) => {
82+
spinner.and_then(|spinner| Some(spinner.failed()));
83+
return Err(err);
84+
}
7485
}
7586
Ok(())
7687
}

coffee_core/src/coffee.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ impl PluginManager for CoffeeManager {
344344
})
345345
}
346346

347-
async fn upgrade(&mut self, repo: &str) -> Result<CoffeeUpgrade, CoffeeError> {
347+
async fn upgrade(&mut self, repo: &str, verbose: bool) -> Result<CoffeeUpgrade, CoffeeError> {
348348
// TODO: upgrade should now be able to upgrade a single plugin
349349
// without affecting other plugins installed from the same repo
350350
let repository = self
@@ -355,8 +355,7 @@ impl PluginManager for CoffeeManager {
355355
let status = repository.upgrade(&self.config.plugins).await?;
356356
for plugins in status.plugins_effected.iter() {
357357
self.remove(plugins).await?;
358-
// FIXME: pass the verbose flag to the upgrade command
359-
self.install(plugins, false, false).await?;
358+
self.install(plugins, verbose, false).await?;
360359
}
361360
self.flush().await?;
362361
Ok(status)

coffee_core/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ pub enum CoffeeOperation {
1111
Install(String, bool, bool),
1212
/// List
1313
List,
14-
// Upgrade(name of the repository)
15-
Upgrade(String),
14+
// Upgrade(name of the repository, verbose run)
15+
Upgrade(String, bool),
1616
Remove(String),
1717
/// Remote(name repository, url of the repository)
1818
Remote(Option<RemoteAction>, bool, Option<String>),

coffee_lib/src/plugin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl Plugin {
149149
}
150150

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

coffee_lib/src/plugin_manager.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub trait PluginManager {
2525
async fn list(&mut self) -> Result<CoffeeList, CoffeeError>;
2626

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

3030
/// add the remote repository to the plugin manager.
3131
async fn add_remote(&mut self, name: &str, url: &str) -> Result<(), CoffeeError>;

0 commit comments

Comments
 (0)