Skip to main content

aopt_core/opt/
style.rs

1/// Option style
2///
3#[non_exhaustive]
4#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
6pub enum Style {
7    #[default]
8    Null,
9
10    /// The style indicate the `NOA` are set base on position.
11    Pos,
12
13    /// The style indicate the `NOA` are set in first position(`@1`).
14    Cmd,
15
16    /// The Main style `NOA` no need set, its callback will always be called.
17    Main,
18
19    /// The style indicate option don't need argument, such as `--boolean`, `-b` or with no prefix `b`.
20    /// Using it with [`Boolean`](https://docs.rs/aopt/latest/aopt/parser/enum.UserStyle.html#variant.Boolean).
21    Boolean,
22
23    /// The style indicate the option need an argument, such as `--int=42`, `-i 42` or `--str=foo`.
24    Argument,
25
26    /// The style indicate option support set multiple option in one string, such as `-ade` means set `-a`, `-d` and `-e`.
27    Combined,
28
29    /// The style indicate option don't need argument, such as `--boolean`, `-b` or with no prefix `b`.
30    /// Using it with [`Flag`](https://docs.rs/aopt/latest/aopt/parser/enum.UserStyle.html#variant.Flag).
31    Flag,
32}
33
34impl std::fmt::Display for Style {
35    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36        match self {
37            Style::Null => {
38                write!(f, "Style::Null")
39            }
40            Style::Pos => {
41                write!(f, "Style::Pos")
42            }
43            Style::Cmd => {
44                write!(f, "Style::Cmd")
45            }
46            Style::Main => {
47                write!(f, "Style::Main")
48            }
49            Style::Boolean => {
50                write!(f, "Style::Boolean")
51            }
52            Style::Argument => {
53                write!(f, "Style::Argument")
54            }
55            Style::Combined => {
56                write!(f, "Style::Combined")
57            }
58            Style::Flag => {
59                write!(f, "Style::Flag")
60            }
61        }
62    }
63}