Skip to content

Commit

Permalink
feat(core): add branch flag to coffee upgrade
Browse files Browse the repository at this point in the history
Signed-off-by: Tarek <[email protected]>
  • Loading branch information
tareknaser committed Jul 4, 2023
1 parent 7c88bed commit 69b7323
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 15 deletions.
10 changes: 8 additions & 2 deletions coffee_cmd/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ pub enum CoffeeCommand {
},
/// upgrade a single repository.
#[clap(arg_required_else_help = true)]
Upgrade { repo: String },
Upgrade {
repo: String,
#[clap(short, long, value_parser, name = "branch")]
branch: Option<String>,
},
/// Print the list of plugins installed in cln.
#[clap(arg_required_else_help = false)]
List {},
Expand Down Expand Up @@ -70,7 +74,9 @@ 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, branch } => {
Self::Upgrade(repo.to_owned(), branch.to_owned())
}
CoffeeCommand::List {} => Self::List,
CoffeeCommand::Setup { cln_conf } => Self::Setup(cln_conf.to_owned()),
CoffeeCommand::Remote { action } => Self::Remote(action.into()),
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 @@ -56,8 +56,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, branch } => {
match coffee.upgrade(&repo, branch).await {
Ok(res) => match res.status {
UpgradeStatus::UpToDate => {
term::info!("Remote repository `{}` is already up to date!", res.repo)
Expand Down
10 changes: 7 additions & 3 deletions coffee_core/src/coffee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,15 +265,19 @@ impl PluginManager for CoffeeManager {
})
}

async fn upgrade(&mut self, repo: &str) -> Result<CoffeeUpgrade, CoffeeError> {
async fn upgrade(
&mut self,
repo: &str,
branch: Option<String>,
) -> Result<CoffeeUpgrade, CoffeeError> {
self.remote_sync().await?;

let repository = self
.repos
.get(repo)
.get_mut(repo)
.ok_or_else(|| error!("Repository with name: `{}` not found", repo))?;

let status = repository.upgrade(&self.config.plugins).await?;
let status = repository.upgrade(&self.config.plugins, branch).await?;
for plugins in status.plugins_effected.iter() {
self.remove(plugins).await?;
// FIXME: pass the verbose flag to the upgrade command
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 @@ -7,8 +7,8 @@ pub enum CoffeeOperation {
Install(String, bool, bool),
/// List(include remotes)
List,
// Upgrade(name of the repository)
Upgrade(String),
// Upgrade(name of the repository, branch)
Upgrade(String, Option<String>),
Remove(String),
/// Remote(name repository, url of the repositoryu)
Remote(RemoteAction),
Expand Down
12 changes: 11 additions & 1 deletion coffee_github/src/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,11 @@ impl Repository for Github {
}
}

async fn upgrade(&self, plugins: &Vec<Plugin>) -> Result<CoffeeUpgrade, CoffeeError> {
async fn upgrade(
&mut self,
plugins: &Vec<Plugin>,
branch: Option<String>,
) -> Result<CoffeeUpgrade, CoffeeError> {
// get the list of the plugins installed from this repository
// TODO: add a field of installed plugins in the repository struct instead
let mut plugins_effected: Vec<String> = vec![];
Expand All @@ -235,6 +239,12 @@ impl Repository for Github {
plugins_effected.push(plugin_name.to_owned());
}
}

// Update the branch if it is specified
if let Some(branch) = branch {
self.branch = branch;
}

// pull the changes from the repository
let status = fast_forward(&self.url.path_string, &self.branch)?;
Ok(CoffeeUpgrade {
Expand Down
8 changes: 6 additions & 2 deletions coffee_lib/src/plugin_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ pub trait PluginManager {
/// return the list of plugins installed by the plugin manager.
async fn list(&mut self) -> Result<CoffeeList, CoffeeError>;

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

/// refresh the storage information about the remote repositories of the plugin manager.
async fn remote_sync(&mut self) -> Result<(), CoffeeError>;
Expand Down
8 changes: 6 additions & 2 deletions coffee_lib/src/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ pub trait Repository: Any {
/// return the list of plugin that are register contained inside the repository.
async fn list(&self) -> Result<Vec<Plugin>, CoffeeError>;

/// upgrade the repository
async fn upgrade(&self, plugins: &Vec<Plugin>) -> Result<CoffeeUpgrade, CoffeeError>;
/// upgrade the repository (with a specific branch).
async fn upgrade(
&mut self,
plugins: &Vec<Plugin>,
branch: Option<String>,
) -> Result<CoffeeUpgrade, CoffeeError>;

/// return the name of the repository.
fn name(&self) -> String;
Expand Down
7 changes: 6 additions & 1 deletion docs/docs-book/src/using-coffee.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,19 @@ To remove an installed plugin, you simply have to run the following command.
coffee remove <plugin_name>
```

## Upgrade a Plugin
## Upgrade a repository

Coffee tightly integrates with git, allowing you to easily upgrade your plugins through the command line interface (CLI). This eliminates the need for tedious tasks such as downloading the latest updates and creating new versions of plugins. To upgrade a plugin, all you need to do is run.
> ✅ Implemented
```bash
coffee upgrade <repo_name>
```

To specify a branch from the git repository. run:
```bash
coffee upgrade <repo_name> --branch <branch_name>
```



## Listing all the plugins
Expand Down

0 comments on commit 69b7323

Please sign in to comment.