From edc495895afa179485c587801c92b2e488fb558b Mon Sep 17 00:00:00 2001 From: Ramses Date: Mon, 11 Dec 2023 21:16:41 +0100 Subject: fix(stats): don't require all fields under [stats] (#1437) Before this change, when configuring only `common_subcommands` and not `common_prefix` (so it would take its default value), atuin produces an error message: ``` Error: could not load client settings Caused by: failed to deserialize: missing field `common_prefix` Location: atuin-client/src/settings.rs:456:26 Error: could not load client settings Caused by: failed to deserialize: missing field `common_prefix` Location: atuin-client/src/settings.rs:456:26 Error:: command not found ``` With this change, the fields can be specified separately and missing fields will take their default values. --- atuin-client/src/settings.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'atuin-client/src') diff --git a/atuin-client/src/settings.rs b/atuin-client/src/settings.rs index c5e72025..93bc64ea 100644 --- a/atuin-client/src/settings.rs +++ b/atuin-client/src/settings.rs @@ -145,18 +145,30 @@ pub enum WordJumpMode { #[derive(Clone, Debug, Deserialize)] pub struct Stats { + #[serde(default = "Stats::common_prefix_default")] pub common_prefix: Vec, // sudo, etc. commands we want to strip off + #[serde(default = "Stats::common_subcommands_default")] pub common_subcommands: Vec, // kubectl, commands we should consider subcommands for } +impl Stats { + fn common_prefix_default() -> Vec { + vec!["sudo", "doas"].into_iter().map(String::from).collect() + } + + fn common_subcommands_default() -> Vec { + vec!["cargo", "go", "git", "npm", "yarn", "pnpm", "kubectl"] + .into_iter() + .map(String::from) + .collect() + } +} + impl Default for Stats { fn default() -> Self { Self { - common_prefix: vec!["sudo", "doas"].into_iter().map(String::from).collect(), - common_subcommands: vec!["cargo", "go", "git", "npm", "yarn", "pnpm", "kubectl"] - .into_iter() - .map(String::from) - .collect(), + common_prefix: Self::common_prefix_default(), + common_subcommands: Self::common_subcommands_default(), } } } -- cgit v1.3.1