Skip to content

Commit

Permalink
feat: branch support in installation
Browse files Browse the repository at this point in the history
  • Loading branch information
royalpinto007 committed Dec 31, 2023
1 parent a9a0523 commit 1ad3b6b
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 7 deletions.
5 changes: 4 additions & 1 deletion coffee_cmd/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub enum CoffeeCommand {
verbose: bool,
#[arg(short, long, action = clap::ArgAction::SetTrue)]
dynamic: bool,
#[arg(short, long, action = clap::ArgAction::SetTrue)]
branch: Option<String>,
},
/// upgrade a single repository.
#[clap(arg_required_else_help = true)]
Expand Down Expand Up @@ -89,7 +91,8 @@ impl From<&CoffeeCommand> for coffee_core::CoffeeOperation {
plugin,
verbose,
dynamic,
} => Self::Install(plugin.to_owned(), *verbose, *dynamic),
branch,
} => Self::Install(plugin.to_owned(), *verbose, *dynamic, branch.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()),
Expand Down
3 changes: 2 additions & 1 deletion coffee_cmd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ async fn main() -> Result<(), CoffeeError> {
plugin,
verbose,
dynamic,
branch,
} => {
let spinner = if !verbose {
Some(term::spinner("Compiling and installing"))
} else {
None
};
let result = coffee.install(&plugin, verbose, dynamic).await;
let result = coffee.install(&plugin, verbose, dynamic, branch).await;
if let Some(spinner) = spinner {
if result.is_ok() {
spinner.finish();
Expand Down
3 changes: 2 additions & 1 deletion coffee_core/src/coffee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ impl PluginManager for CoffeeManager {
plugin: &str,
verbose: bool,
try_dynamic: bool,
_branch: Option<String>,
) -> Result<(), CoffeeError> {
log::debug!("installing plugin: {plugin}");
// keep track if the plugin is successfully installed
Expand Down Expand Up @@ -355,7 +356,7 @@ impl PluginManager for CoffeeManager {
let status = repository.upgrade(&self.config.plugins).await?;
for plugins in status.plugins_effected.iter() {
self.remove(plugins).await?;
self.install(plugins, verbose, false).await?;
self.install(plugins, verbose, false, None).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 @@ -7,8 +7,8 @@ pub use coffee_lib as lib;

#[derive(Clone, Debug)]
pub enum CoffeeOperation {
/// Install(plugin name, verbose run, dynamic installation)
Install(String, bool, bool),
/// Install(plugin name, verbose run, dynamic installation, branch)
Install(String, bool, bool, Option<String>),
/// List
List,
// Upgrade(name of the repository, verbose run)
Expand Down
2 changes: 1 addition & 1 deletion coffee_httpd/src/httpd/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ async fn coffee_install(
let try_dynamic = body.try_dynamic;

let mut coffee = data.coffee.lock().await;
let result = coffee.install(plugin, false, try_dynamic).await;
let result = coffee.install(plugin, false, try_dynamic, None).await;

handle_httpd_response!(result, "Plugin '{plugin}' installed successfully")
}
Expand Down
1 change: 1 addition & 0 deletions coffee_lib/src/plugin_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub trait PluginManager {
plugins: &str,
verbose: bool,
try_dynamic: bool,
branch: Option<String>,
) -> Result<(), CoffeeError>;

// remove a plugin by name, return an error if some error happens.
Expand Down
2 changes: 1 addition & 1 deletion coffee_plugin/src/plugin/plugin_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl RPCCommand<State> for CoffeeInstall {
let rt = Runtime::new().unwrap();

let request: InstallReq = serde_json::from_value(request)?;
rt.block_on(coffee.install(&request.name, false, true))
rt.block_on(coffee.install(&request.name, false, true, None))
.map_err(from)?;
Ok(json!({}))
}
Expand Down
7 changes: 7 additions & 0 deletions docs/docs-book/src/using-coffee.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ To install a plugin statically, you simply need to run.
coffee install <plugin_name>
```

#### Branch Specification for Plugin Installation

User can install a plugin from a specific branch using the command:
```bash
coffee install <plugin_name> --branch <branch_name>
```

### Removing a Plugin

> ✅ Implemented
Expand Down

0 comments on commit 1ad3b6b

Please sign in to comment.