hedl_cli/cli/mod.rs
1// Dweve HEDL - Hierarchical Entity Data Language
2//
3// Copyright (c) 2025 Dweve IP B.V. and individual contributors.
4//
5// SPDX-License-Identifier: Apache-2.0
6//
7// Licensed under the Apache License, Version 2.0 (the "License");
8// you may not use this file except in compliance with the License.
9// You may obtain a copy of the License in the LICENSE file at the
10// root of this repository or at: http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18//! CLI command definitions and argument parsing.
19//!
20//! This module contains all command-line interface structures for the HEDL CLI,
21//! organized into logical categories for better maintainability.
22//!
23//! # Organization
24//!
25//! Commands are organized into the following modules:
26//!
27//! - `core`: Core commands (validate, format, lint, inspect, stats)
28//! - `conversion`: Format conversion commands (JSON, YAML, XML, CSV, Parquet)
29//! - `batch`: Batch processing commands (batch-validate, batch-format, batch-lint)
30//! - `completion`: Shell completion generation
31//!
32//! # Design Principles
33//!
34//! - **Single Responsibility**: Each submodule handles one category of commands
35//! - **Consistent API**: All commands follow the same argument patterns
36//! - **Type Safety**: Strongly typed arguments with validation
37//! - **Extensibility**: Easy to add new commands within existing categories
38
39mod batch;
40mod completion;
41mod conversion;
42mod core;
43
44use clap::Subcommand;
45
46pub use batch::BatchCommands;
47pub use completion::CompletionCommands;
48pub use conversion::ConversionCommands;
49pub use core::CoreCommands;
50
51/// Top-level CLI commands enum.
52///
53/// This is the main command dispatcher that delegates to specialized command
54/// categories. Each variant represents a category of related commands.
55///
56/// # Architecture
57///
58/// The commands are organized hierarchically:
59///
60/// ```text
61/// Commands
62/// ├── Core (validate, format, lint, inspect, stats)
63/// ├── Conversion (JSON, YAML, XML, CSV, Parquet)
64/// ├── Batch (batch-validate, batch-format, batch-lint)
65/// └── Completion (shell completion generation)
66/// ```
67///
68/// # Examples
69///
70/// ```no_run
71/// use clap::Parser;
72/// use hedl_cli::cli::Commands;
73///
74/// #[derive(Parser)]
75/// struct Cli {
76/// #[command(subcommand)]
77/// command: Commands,
78/// }
79/// ```
80#[derive(Subcommand)]
81pub enum Commands {
82 /// Core commands (validate, format, lint, inspect, stats).
83 #[command(flatten)]
84 Core(CoreCommands),
85
86 /// Conversion commands (JSON, YAML, XML, CSV, Parquet).
87 #[command(flatten)]
88 Conversion(ConversionCommands),
89
90 /// Batch processing commands (batch-validate, batch-format, batch-lint).
91 #[command(flatten)]
92 Batch(BatchCommands),
93
94 /// Shell completion generation.
95 #[command(flatten)]
96 Completion(CompletionCommands),
97}
98
99impl Commands {
100 /// Execute the command with the provided arguments.
101 ///
102 /// This method dispatches to the appropriate command handler based on the
103 /// command variant.
104 ///
105 /// # Returns
106 ///
107 /// Returns `Ok(())` on successful execution, or an error message on failure.
108 ///
109 /// # Errors
110 ///
111 /// Returns `Err` if:
112 /// - File I/O fails
113 /// - Parsing or validation fails
114 /// - Conversion fails
115 /// - Any other command-specific error occurs
116 pub fn execute(self) -> Result<(), crate::error::CliError> {
117 match self {
118 Commands::Core(cmd) => cmd.execute(),
119 Commands::Conversion(cmd) => cmd.execute(),
120 Commands::Batch(cmd) => cmd.execute(),
121 Commands::Completion(cmd) => cmd.execute(),
122 }
123 }
124}