1use crate::cli::ContextAction;
2use crate::error::Result;
3use crate::hooks::{
4 delete_pending_context, read_pending_context, write_pending_context, PendingContext,
5};
6
7use super::util::find_git_dir;
8
9pub fn run(action: ContextAction) -> Result<()> {
10 let git_dir = find_git_dir()?;
11
12 match action {
13 ContextAction::Set {
14 task,
15 reasoning,
16 dependencies,
17 tags,
18 } => {
19 let ctx = PendingContext {
20 task,
21 reasoning,
22 dependencies,
23 tags,
24 };
25 write_pending_context(&git_dir, &ctx)?;
26 eprintln!("pending context saved");
27 }
28 ContextAction::Show => match read_pending_context(&git_dir)? {
29 Some(ctx) => {
30 println!("{}", serde_json::to_string_pretty(&ctx).unwrap_or_default());
31 }
32 None => {
33 eprintln!("no pending context");
34 }
35 },
36 ContextAction::Clear => {
37 delete_pending_context(&git_dir)?;
38 eprintln!("pending context cleared");
39 }
40 }
41
42 Ok(())
43}