command_vault/db/
models.rs

1//! Database models for command-vault
2//! 
3//! This module defines the core data structures used throughout the application.
4
5use chrono::{DateTime, Utc};
6use serde::{Deserialize, Serialize};
7
8/// Represents a command with its metadata.
9/// 
10/// A command includes the actual command string, execution directory,
11/// timestamp, tags, and parameters.
12/// 
13/// # Example
14/// ```rust
15/// use command_vault::db::models::Command;
16/// use chrono::Utc;
17/// 
18/// let cmd = Command {
19///     id: None,
20///     command: "git push origin main".to_string(),
21///     timestamp: Utc::now(),
22///     directory: "/project".to_string(),
23///     tags: vec!["git".to_string()],
24///     parameters: vec![],
25/// };
26/// ```
27#[derive(Debug, Clone, Serialize, Deserialize)]
28pub struct Command {
29    /// Unique identifier for the command
30    pub id: Option<i64>,
31    
32    /// The actual command string
33    pub command: String,
34    
35    /// When the command was created or last modified
36    pub timestamp: DateTime<Utc>,
37    
38    /// Directory where the command should be executed
39    pub directory: String,
40    
41    /// Tags associated with the command
42    #[serde(skip_serializing_if = "Vec::is_empty", default)]
43    pub tags: Vec<String>,
44    
45    /// Parameters that can be substituted in the command
46    #[serde(skip_serializing_if = "Vec::is_empty", default)]
47    pub parameters: Vec<Parameter>,
48}
49
50/// Represents a parameter that can be substituted in a command.
51/// 
52/// Parameters allow commands to be more flexible by providing
53/// placeholders that can be filled in at runtime.
54/// 
55/// # Example
56/// ```rust
57/// use command_vault::db::models::Parameter;
58/// 
59/// let param = Parameter {
60///     name: "branch".to_string(),
61///     description: Some("Git branch name".to_string()),
62/// };
63/// ```
64#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
65pub struct Parameter {
66    /// Name of the parameter (used in substitution)
67    pub name: String,
68    
69    /// Optional description of what the parameter does
70    pub description: Option<String>,
71}
72
73impl Parameter {
74    pub fn new(name: String) -> Self {
75        Self {
76            name,
77            description: None,
78        }
79    }
80
81    pub fn with_description(name: String, description: Option<String>) -> Self {
82        Self {
83            name,
84            description,
85        }
86    }
87}