flowcode_core/
spec.rs

1#[cfg(feature = "json")]
2use serde::Serialize;
3
4#[derive(Debug, Clone)]
5#[cfg_attr(feature = "json", derive(Serialize))]
6pub struct CommandSpec {
7    pub name: &'static str,
8    pub description: &'static str,
9    pub syntax: &'static str,
10    pub arguments: &'static [ArgumentSpec], // New field for argument details
11}
12
13#[derive(Debug, Clone)]
14#[cfg_attr(feature = "json", derive(Serialize))]
15pub struct ArgumentSpec {
16    pub name: &'static str,
17    pub description: &'static str,
18    pub required: bool,
19}
20
21pub static SPECS: &[CommandSpec] = &[
22    CommandSpec {
23        name: "combine",
24        description: "Combines multiple numerical data series into a single series by averaging.",
25        syntax: "combine <series_1_path_or_data> <series_2_path_or_data> ... <series_n_path_or_data>",
26        arguments: &[
27            ArgumentSpec { name: "<series_data>", description: "Path to a data file or direct numerical data for a series. At least two series are required.", required: true },
28        ],
29    },
30    CommandSpec {
31        name: "predict",
32        description: "Predicts the next numeric value based on linear extrapolation (2*last - second_last)",
33        syntax: "predict <number1> <number2> ... <numberN>",
34        arguments: &[
35            ArgumentSpec {
36                name: "<numbers>",
37                description: "A series of numbers. At least two numbers are required for prediction.",
38                required: true,
39            },
40        ],
41    },
42    CommandSpec {
43        name: "show",
44        description: "Displays the logged commands and their outputs from the current session.",
45        syntax: "show",
46        arguments: &[],
47    },
48    CommandSpec {
49        name: "help",
50        description: "Displays this help message or detailed information about commands.",
51        syntax: "help [command_name] [--json]",
52        arguments: &[
53            ArgumentSpec { name: "[command_name]", description: "Optional: The name of a command to get detailed help for.", required: false },
54            ArgumentSpec { name: "--json", description: "Optional: Output the help information in JSON format.", required: false },
55        ],
56    },
57    CommandSpec {
58        name: "select",
59        description: "Selects specific columns from a dataset.",
60        syntax: "select <column1> [column2] ... [columnN]",
61        arguments: &[
62            ArgumentSpec { name: "<columns>", description: "Columns to select from the dataset.", required: true },
63        ],
64    },
65    CommandSpec {
66        name: "filter",
67        description: "Filters rows in a dataset based on a condition.",
68        syntax: "filter <condition>",
69        arguments: &[
70            ArgumentSpec { name: "<condition>", description: "Condition to filter rows (e.g., 'age > 30').", required: true },
71        ],
72    },
73    CommandSpec {
74        name: "group",
75        description: "Groups data by specified columns for aggregation.",
76        syntax: "group <column1> [column2] ... [columnN]",
77        arguments: &[
78            ArgumentSpec { name: "<columns>", description: "Columns to group by.", required: true },
79        ],
80    },
81    CommandSpec {
82        name: "join",
83        description: "Joins two datasets based on a common key or condition.",
84        syntax: "join <dataset1> <dataset2> <join_condition>",
85        arguments: &[
86            ArgumentSpec { name: "<dataset1>", description: "First dataset to join.", required: true },
87            ArgumentSpec { name: "<dataset2>", description: "Second dataset to join.", required: true },
88            ArgumentSpec { name: "<join_condition>", description: "Condition or key to join datasets (e.g., 'id = id').", required: true },
89        ],
90    },
91    CommandSpec {
92        name: "sort",
93        description: "Sorts the dataset based on specified columns.",
94        syntax: "sort <column1> [column2] ... [columnN] [order]",
95        arguments: &[
96            ArgumentSpec { name: "<columns>", description: "Columns to sort by.", required: true },
97            ArgumentSpec { name: "[order]", description: "Optional: Sort order ('asc' or 'desc'). Default is 'asc'.", required: false },
98        ],
99    },
100    CommandSpec {
101        name: "load",
102        description: "Loads data from a file or source into a DuckDB table.",
103        syntax: "load <file_path_or_source> [table_name]",
104        arguments: &[
105            ArgumentSpec { name: "<file_path_or_source>", description: "Path to the file or data source to load.", required: true },
106            ArgumentSpec { name: "[table_name]", description: "Optional: Name of the table to create. Defaults to 'loaded_data'.", required: false },
107        ],
108    },
109    CommandSpec {
110        name: "sql",
111        description: "Executes a direct SQL query.",
112        syntax: "sql <query>",
113        arguments: &[
114            ArgumentSpec { name: "<query>", description: "SQL query to execute.", required: true },
115        ],
116    },
117    // Future commands like 'clear', 'exit' (if they become true commands) would go here.
118];
119
120// Helper function to get SPECS as JSON, requires 'json' feature
121#[cfg(feature = "json")]
122pub fn get_specs_json() -> Result<String, serde_json::Error> {
123    serde_json::to_string_pretty(&SPECS)
124}