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    // Future commands like 'clear', 'exit' (if they become true commands) would go here.
58];
59
60// Helper function to get SPECS as JSON, requires 'json' feature
61#[cfg(feature = "json")]
62pub fn get_specs_json() -> Result<String, serde_json::Error> {
63    serde_json::to_string_pretty(&SPECS)
64}