Skip to main content

oxdock_parser/
command.rs

1use crate::ast::{Arg, StepKind};
2use anyhow::Result;
3
4/// Metadata for a single command argument.
5pub struct ArgSpec {
6    pub name: &'static str,
7    pub arg_type: &'static str,
8    pub description: &'static str,
9    pub io: IoDirection,
10    pub index: usize,
11    pub required: bool,
12    pub fallback_stream: Option<Stream>,
13}
14
15/// Data direction for an argument.
16#[derive(Debug, Clone, Copy, PartialEq, Eq)]
17pub enum IoDirection {
18    Read,
19    Write,
20}
21
22/// Stream type for fallback or default output.
23#[derive(Debug, Clone, Copy, PartialEq, Eq)]
24pub enum Stream {
25    Stdin,
26    Stdout,
27    Stderr,
28}
29
30/// Metadata for a single flag.
31pub struct FlagSpec {
32    pub name: &'static str,
33    pub long: &'static str,
34    pub value_type: FlagValueType,
35    pub required: bool,
36    pub description: &'static str,
37}
38
39/// Type of value a flag accepts.
40#[derive(Debug, Clone, Copy, PartialEq, Eq)]
41pub enum FlagValueType {
42    /// Boolean flag (no value required).
43    Flag,
44    /// String-valued flag.
45    String,
46    /// Integer-valued flag.
47    Int,
48}
49
50/// Complete metadata for a command.
51pub struct CommandMeta {
52    pub name: &'static str,
53    pub syntax: &'static str,
54    pub summary: &'static str,
55    pub description: &'static str,
56    pub args: &'static [ArgSpec],
57    pub flags: &'static [FlagSpec],
58    pub default_output: Option<Stream>,
59    pub examples: &'static [Example],
60}
61
62/// An executable example for a command.
63pub struct Example {
64    pub name: &'static str,
65    pub fence_meta: Option<&'static str>,
66    pub code: &'static str,
67}
68
69/// Trait for command metadata and lowering. No execution types.
70///
71/// This trait lives in `oxdock-parser` and has zero dependencies on
72/// `oxdock-core`. Execution dispatch is handled separately by the
73/// `define_pipeline!` macro in `oxdock-core`.
74pub trait CommandSpec {
75    const NAME: &'static str;
76
77    fn metadata() -> CommandMeta;
78    fn lower(flags: Vec<(String, Arg)>, args: Vec<Arg>) -> Result<StepKind>;
79}