Skip to content

Commit 8a856c2

Browse files
committed
refactor: use SmartDefault for RegistryConfig, default auto_discover to true
1 parent cac339b commit 8a856c2

6 files changed

Lines changed: 19 additions & 13 deletions

File tree

Cargo.lock

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ uuid = { version = "1", features = ["serde", "v4"] }
3535
chrono = { version = "0.4", features = ["serde"] }
3636
thiserror = "2"
3737
derive_more = { version = "1", default-features = false, features = ["full"] }
38+
smart-default = "0.7"
3839
tokio = { version = "1", features = ["full"] }
3940
tokio-util = { version = "0.7", features = ["rt"] }
4041
extism = "1"

crates/hm/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ hm-plugin-protocol = { workspace = true }
7171
hm-util = { workspace = true }
7272
schemars = { workspace = true }
7373
semver = { workspace = true }
74+
smart-default = { workspace = true }
7475
once_cell = "1"
7576
hex = "0.4"
7677

crates/hm/src/cli/plugin.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,7 @@ pub async fn run(cmd: PluginCommand) -> Result<()> {
5050

5151
#[allow(clippy::unused_async)]
5252
async fn list() -> Result<()> {
53-
let reg = PluginRegistry::load(RegistryConfig {
54-
auto_discover: true,
55-
..Default::default()
56-
})?;
53+
let reg = PluginRegistry::load(RegistryConfig::default())?;
5754
if reg.manifests().count() == 0 {
5855
println!("No plugins installed.");
5956
println!();
@@ -78,10 +75,7 @@ async fn list() -> Result<()> {
7875

7976
#[allow(clippy::unused_async)]
8077
async fn info(name: &str) -> Result<()> {
81-
let reg = PluginRegistry::load(RegistryConfig {
82-
auto_discover: true,
83-
..Default::default()
84-
})?;
78+
let reg = PluginRegistry::load(RegistryConfig::default())?;
8579
let m = reg
8680
.manifests()
8781
.find(|m| m.name == name)

crates/hm/src/cli/version.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ use crate::plugin::{PluginRegistry, RegistryConfig};
1010
///
1111
/// Returns an error if the plugin registry cannot be loaded.
1212
pub async fn run() -> Result<()> {
13-
let reg = PluginRegistry::load(RegistryConfig {
14-
auto_discover: true,
15-
..Default::default()
16-
})?;
13+
let reg = PluginRegistry::load(RegistryConfig::default())?;
1714
println!("hm {}", env!("CARGO_PKG_VERSION"));
1815
println!("plugin api version: {HM_PLUGIN_API_VERSION}");
1916
let count = reg.manifests().count();

crates/hm/src/plugin/registry.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ use super::manifest::{ManifestError, validate_standalone};
2727
use super::paths;
2828
use crate::error::HmError;
2929

30-
#[derive(Debug, Default)]
30+
#[derive(Debug, smart_default::SmartDefault)]
3131
pub struct RegistryConfig {
3232
/// If `false`, skip discovery and only registers explicitly added
3333
/// plugins. Used by integration tests.
34+
#[default = true]
3435
pub auto_discover: bool,
3536
/// Extra plugin paths to load (in addition to discovery). Used by
3637
/// tests to load fixture plugins.

0 commit comments

Comments
 (0)