Skip to content

Commit

Permalink
feat: add enabled field in Plugin struct
Browse files Browse the repository at this point in the history
- Added the enabled field in the plugin struct to track plugin status
- Plugins are now set as enabled by default upon installation
- Modified coffee list to display the enabled status of each plugin
- For backward compatibility, assume plugins are enabled if plugin.enabled is None

This sets the groundwork for implementing coffee enable and coffee disablecommands

Signed-off-by: Tarek <[email protected]>
  • Loading branch information
tareknaser authored and vincenzopalazzo committed Feb 13, 2024
1 parent 560da0a commit 790dc64
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
11 changes: 10 additions & 1 deletion coffee_cmd/src/coffee_term/command_show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,31 @@ pub fn show_list(coffee_list: Result<CoffeeList, CoffeeError>) -> Result<(), Cof

term::println(
term::format::bold("●"),
term::format::tertiary("Plugin installed"),
term::format::tertiary("Plugins installed"),
);
let mut table = radicle_term::Table::new(TableOptions::bordered());
table.push([
term::format::dim(String::from("●")),
term::format::bold(String::from("Language")),
term::format::bold(String::from("Name")),
term::format::bold(String::from("Enabled?")),
term::format::bold(String::from("Exec path")),
]);
table.divider();

for plugin in &remotes.plugins {
// Get whether the plugin is enabled
// If enabled is None, it means the plugin is enabled by default for backward compatibility.
let enabled = plugin.enabled.unwrap_or(true);
table.push([
term::format::positive("●").into(),
term::format::highlight(plugin.lang.to_string()),
term::format::bold(plugin.name()),
if enabled {
term::format::positive("yes").into()
} else {
term::format::negative("no").into()
},
term::format::highlight(plugin.exec_path.to_owned()),
])
}
Expand Down
2 changes: 2 additions & 0 deletions coffee_core/src/coffee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ impl PluginManager for CoffeeManager {
let path = plugin.configure(verbose).await?;
log::debug!("runnable plugin path {path}");
if !try_dynamic {
// mark the plugin enabled
plugin.enabled = Some(true);
self.config.plugins.push(plugin);
log::debug!("path coffee conf: {}", self.coffee_cln_config.path);
self.coffee_cln_config
Expand Down
3 changes: 3 additions & 0 deletions coffee_github/src/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ impl Github {
plugin_lang,
conf.clone(),
commit_id.clone(),
// The plugin for now is not installed, so it's
// neither enabled or disabled
None,
);

debug!("new plugin: {:?}", plugin);
Expand Down
4 changes: 4 additions & 0 deletions coffee_lib/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ pub struct Plugin {
conf: Option<Conf>,
/// FIXME: this field shouldn't be optional
pub commit: Option<String>,
/// Optional for now to be backward compatible
pub enabled: Option<bool>,
}

impl Plugin {
Expand All @@ -115,6 +117,7 @@ impl Plugin {
plugin_lang: PluginLang,
config: Option<Conf>,
commit_id: Option<String>,
enabled: Option<bool>,
) -> Self {
Plugin {
name: name.to_owned(),
Expand All @@ -123,6 +126,7 @@ impl Plugin {
lang: plugin_lang,
conf: config,
commit: commit_id,
enabled,
}
}

Expand Down

0 comments on commit 790dc64

Please sign in to comment.