Skip to content

Commit edaf69d

Browse files
committed
update enable hook func names, add serde default
1 parent b410760 commit edaf69d

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

crates/q_cli/src/cli/chat/context.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub const AMAZONQ_FILENAME: &str = "AmazonQ.md";
2828

2929
/// Configuration for context files, containing paths to include in the context.
3030
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
31+
#[serde(default)]
3132
pub struct ContextConfig {
3233
/// List of file paths or glob patterns to include in the context.
3334
pub paths: Vec<String>,
@@ -503,11 +504,10 @@ impl ContextManager {
503504
self.save_config(global).await
504505
}
505506

506-
/// Sets the "disabled" field on any [`Hook`] with the given name to be true or false
507+
/// Sets the "disabled" field on any [`Hook`] with the given name
507508
/// # Arguments
508-
/// * `enable` - If true, the "disabled" field are is to false. If false, the "disabled" field
509-
/// is set to true
510-
pub async fn enable_hook(&mut self, name: &str, global: bool, enable: bool) -> Result<()> {
509+
/// * `disable` - Set "disabled" field to this value
510+
pub async fn set_hook_disabled(&mut self, name: &str, global: bool, disable: bool) -> Result<()> {
511511
let config = self.get_config_mut(global);
512512

513513
config
@@ -516,24 +516,23 @@ impl ContextManager {
516516
.iter_mut()
517517
.chain(config.hooks.per_prompt.iter_mut())
518518
.filter(|h| h.name == name)
519-
.for_each(|h| h.disabled = !enable);
519+
.for_each(|h| h.disabled = disable);
520520

521521
self.save_config(global).await
522522
}
523523

524-
/// Sets the "disabled" field on all [`Hook`]s to be true or false
524+
/// Sets the "disabled" field on all [`Hook`]s
525525
/// # Arguments
526-
/// * `enable` - If true, all "disabled" fields are set to false. If false, all "disabled"
527-
/// fields are set to true
528-
pub async fn enable_all_hooks(&mut self, global: bool, enable: bool) -> Result<()> {
526+
/// * `disable` - Set all "disabled" fields to this value
527+
pub async fn set_all_hooks_disabled(&mut self, global: bool, disable: bool) -> Result<()> {
529528
let config = self.get_config_mut(global);
530529

531530
config
532531
.hooks
533532
.conversation_start
534533
.iter_mut()
535534
.chain(config.hooks.per_prompt.iter_mut())
536-
.for_each(|h| h.disabled = !enable);
535+
.for_each(|h| h.disabled = disable);
537536

538537
self.save_config(global).await
539538
}

crates/q_cli/src/cli/chat/hooks.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ pub enum HookType {
9595
}
9696

9797
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
98+
#[serde(default)]
9899
pub struct HookConfig {
99100
pub conversation_start: Vec<Hook>,
100101
pub per_prompt: Vec<Hook>,
@@ -233,15 +234,15 @@ impl HookExecutor {
233234
let timeout = Duration::from_millis(hook.timeout_ms);
234235

235236
// Run with timeout
236-
match tokio::time::timeout(timeout, command_future).await? {
237-
Ok(result) => match result.exit_status.unwrap_or(0) {
238-
0 => Ok(result.stdout),
239-
code => Err(eyre!("command returned non-zero exit code: {}", code)),
237+
match tokio::time::timeout(timeout, command_future).await {
238+
Ok(result) => {
239+
let result = result?;
240+
match result.exit_status.unwrap_or(0) {
241+
0 => Ok(result.stdout),
242+
code => Err(eyre!("command returned non-zero exit code: {}", code)),
243+
}
240244
},
241-
Err(_) => Err(eyre!(
242-
"command failed to start or timed out after {} ms",
243-
timeout.as_millis()
244-
)),
245+
Err(_) => Err(eyre!("command timed out after {} ms", timeout.as_millis())),
245246
}
246247
}
247248

0 commit comments

Comments
 (0)