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