Skip to main content

evo/domain/
command.rs

1use serde::{Deserialize, Serialize};
2use std::path::{Path, PathBuf};
3
4pub const RUN_FILE: &str = "run";
5pub const ENV_FILE: &str = ".env";
6pub const MANIFEST_FILE: &str = "manifest.json";
7pub const README_FILE: &str = "README.md";
8pub const INDEX_DB_FILE: &str = "index.db";
9
10pub const BUILTIN_COMMANDS: &[&str] = &[
11    "create", "update", "ls", "show", "rm", "run", "search", "reindex", "env",
12];
13
14#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
15#[serde(deny_unknown_fields)]
16pub struct CommandManifest {
17    pub name: String,
18    pub description: String,
19    #[serde(default, skip_serializing_if = "Option::is_none")]
20    pub tags: Option<Vec<String>>,
21}
22
23#[derive(Debug)]
24pub struct CommandPayload {
25    pub manifest: CommandManifest,
26    pub run: Option<String>,
27    pub readme: Option<ReadmePatch>,
28}
29
30#[derive(Clone, Debug, Serialize, PartialEq, Eq)]
31pub struct CommandSummary {
32    pub name: String,
33    pub description: String,
34    #[serde(skip_serializing_if = "Option::is_none")]
35    pub tags: Option<Vec<String>>,
36}
37
38#[derive(Clone, Debug, Serialize, PartialEq, Eq)]
39pub struct CommandListEntry {
40    pub name: String,
41    pub description: String,
42    #[serde(skip_serializing_if = "Option::is_none")]
43    pub tags: Option<Vec<String>>,
44    #[serde(rename = "runner")]
45    pub runner_path: String,
46    #[serde(rename = "readme")]
47    pub readme_path: String,
48    pub readme_exists: bool,
49    #[serde(skip_serializing_if = "Option::is_none")]
50    pub env_keys: Option<Vec<String>>,
51}
52
53#[derive(Clone, Debug, Serialize)]
54pub struct CommandDetails {
55    pub manifest: CommandManifest,
56    pub run: String,
57    #[serde(skip_serializing_if = "Option::is_none")]
58    pub env_keys: Option<Vec<String>>,
59    #[serde(skip_serializing_if = "Option::is_none")]
60    pub readme: Option<String>,
61}
62
63#[derive(Debug, Clone, PartialEq, Eq)]
64pub struct CommandSpec {
65    pub root: PathBuf,
66    pub runner_path: PathBuf,
67    pub manifest_path: PathBuf,
68    pub env_path: PathBuf,
69    pub readme_path: PathBuf,
70}
71
72impl CommandSpec {
73    pub fn new(commands_root: &Path, name: &str) -> Self {
74        Self::from_root(commands_root.join(name))
75    }
76
77    pub fn from_root(root: PathBuf) -> Self {
78        Self {
79            runner_path: root.join(RUN_FILE),
80            manifest_path: root.join(MANIFEST_FILE),
81            env_path: root.join(ENV_FILE),
82            readme_path: root.join(README_FILE),
83            root,
84        }
85    }
86}
87
88#[derive(Debug)]
89pub enum ReadmePatch {
90    Set(String),
91}