Skip to main content

appcore_args/
error.rs

1// =============================================================================
2//        #######
3//     ###       ###     F: error.rs
4//    ##   ## ##   ##    P: AppCore-Runtime
5//         ## ##
6//                       C: 2026/08/19 12:52:57 by dnettoRaw
7//    ##   ## ##   ##    U: 2026/08/19 13:34:54 by dnettoRaw
8//      ###########      S: 1.0.1-rc.8
9// =============================================================================
10
11use std::fmt;
12
13#[derive(Clone, Copy, Debug, PartialEq, Eq)]
14pub enum CliErrorKind {
15    InvalidInput,
16    InvalidSpecification,
17    UnknownOption,
18    UnexpectedArgument,
19    MissingCommand,
20    MissingOption,
21    MissingValue,
22    InvalidValue,
23    DuplicateOption,
24    OptionConflict,
25    MissingRequirement,
26}
27
28#[derive(Clone, Debug, PartialEq, Eq)]
29pub struct CliError {
30    kind: CliErrorKind,
31    message: String,
32}
33
34impl CliError {
35    pub fn new(kind: CliErrorKind, message: impl Into<String>) -> Self {
36        Self {
37            kind,
38            message: message.into(),
39        }
40    }
41
42    pub fn kind(&self) -> CliErrorKind {
43        self.kind
44    }
45}
46
47impl fmt::Display for CliError {
48    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
49        formatter.write_str(&self.message)
50    }
51}
52
53impl std::error::Error for CliError {}