Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: branch support in installation #224

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)]
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>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This value isn't used anywhere

royalpinto007 marked this conversation as resolved.
Show resolved Hide resolved
) -> 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?;
royalpinto007 marked this conversation as resolved.
Show resolved Hide resolved
royalpinto007 marked this conversation as resolved.
Show resolved Hide resolved
}
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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idealy, you should also handle changing the httpd request to coffee.install() method
You can add the field to Install struct in coffee_lib/src/types/mod.rs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you meant this, but I am not sure if this is correct- d726c11

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you meant this, but I am not sure if this is correct- d726c11

Correct, but why you are not passing the branch variable down the function call? I am really confused

It is easy, use the following code

Suggested change
let result = coffee.install(plugin, false, try_dynamic, None).await;
let branch = body.branch;
let result = coffee.install(plugin, false, try_dynamic, branch).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))
royalpinto007 marked this conversation as resolved.
Show resolved Hide resolved
.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
Loading