memvid_cli/commands/
binding.rs

1//! Commands for managing memory bindings to dashboard
2
3use std::path::PathBuf;
4
5use anyhow::Result;
6use clap::Args;
7use memvid_core::Memvid;
8
9/// Arguments for the binding command
10#[derive(Args)]
11pub struct BindingArgs {
12    /// Path to the MV2 file
13    pub file: PathBuf,
14
15    /// Output as JSON
16    #[arg(long)]
17    pub json: bool,
18}
19
20/// Handle the binding command
21pub fn handle_binding(args: BindingArgs) -> Result<()> {
22    let mem = Memvid::open(&args.file)?;
23
24    if let Some(binding) = mem.get_memory_binding() {
25        if args.json {
26            let json = serde_json::json!({
27                "memory_id": binding.memory_id.to_string(),
28                "memory_name": binding.memory_name,
29                "bound_at": binding.bound_at.to_rfc3339(),
30                "api_url": binding.api_url,
31            });
32            println!("{}", serde_json::to_string_pretty(&json)?);
33        } else {
34            println!("Memory Binding:");
35            println!("  Memory ID:   {}", binding.memory_id);
36            println!("  Memory Name: {}", binding.memory_name);
37            println!("  Bound At:    {}", binding.bound_at.to_rfc3339());
38            println!("  API URL:     {}", binding.api_url);
39        }
40    } else if args.json {
41        println!("null");
42    } else {
43        println!("This file is not bound to any memory.");
44    }
45
46    Ok(())
47}