]>
Commit | Line | Data |
---|---|---|
9c376795 FG |
1 | #[allow(unused)] |
2 | use crate::Arg; | |
3 | #[allow(unused)] | |
4 | use crate::Command; | |
5 | ||
fe692bf9 FG |
6 | #[derive(Default, Copy, Clone, Debug, PartialEq, Eq)] |
7 | pub(crate) struct AppFlags(u32); | |
8 | ||
9 | impl AppFlags { | |
10 | pub(crate) fn set(&mut self, setting: AppSettings) { | |
11 | self.0 |= setting.bit(); | |
12 | } | |
13 | ||
14 | pub(crate) fn unset(&mut self, setting: AppSettings) { | |
15 | self.0 &= !setting.bit(); | |
16 | } | |
17 | ||
18 | pub(crate) fn is_set(&self, setting: AppSettings) -> bool { | |
19 | self.0 & setting.bit() != 0 | |
20 | } | |
21 | ||
22 | pub(crate) fn insert(&mut self, other: Self) { | |
23 | self.0 |= other.0; | |
24 | } | |
25 | } | |
9c376795 | 26 | |
fe692bf9 FG |
27 | impl std::ops::BitOr for AppFlags { |
28 | type Output = Self; | |
9c376795 | 29 | |
fe692bf9 FG |
30 | fn bitor(mut self, rhs: Self) -> Self::Output { |
31 | self.insert(rhs); | |
32 | self | |
9c376795 FG |
33 | } |
34 | } | |
35 | ||
36 | /// Application level settings, which affect how [`Command`] operates | |
37 | /// | |
38 | /// **NOTE:** When these settings are used, they apply only to current command, and are *not* | |
39 | /// propagated down or up through child or parent subcommands | |
40 | /// | |
41 | /// [`Command`]: crate::Command | |
42 | #[derive(Debug, PartialEq, Copy, Clone)] | |
fe692bf9 | 43 | #[repr(u8)] |
9c376795 FG |
44 | pub(crate) enum AppSettings { |
45 | IgnoreErrors, | |
46 | AllowHyphenValues, | |
47 | AllowNegativeNumbers, | |
48 | AllArgsOverrideSelf, | |
49 | AllowMissingPositional, | |
50 | TrailingVarArg, | |
51 | DontDelimitTrailingValues, | |
52 | InferLongArgs, | |
53 | InferSubcommands, | |
54 | SubcommandRequired, | |
55 | AllowExternalSubcommands, | |
56 | Multicall, | |
57 | SubcommandsNegateReqs, | |
58 | ArgsNegateSubcommands, | |
59 | SubcommandPrecedenceOverArg, | |
4b012472 | 60 | FlattenHelp, |
9c376795 FG |
61 | ArgRequiredElseHelp, |
62 | NextLineHelp, | |
63 | DisableColoredHelp, | |
64 | DisableHelpFlag, | |
65 | DisableHelpSubcommand, | |
66 | DisableVersionFlag, | |
67 | PropagateVersion, | |
68 | Hidden, | |
69 | HidePossibleValues, | |
70 | HelpExpected, | |
71 | NoBinaryName, | |
72 | #[allow(dead_code)] | |
73 | ColorAuto, | |
74 | ColorAlways, | |
75 | ColorNever, | |
76 | Built, | |
77 | BinNameBuilt, | |
78 | } | |
79 | ||
fe692bf9 FG |
80 | impl AppSettings { |
81 | fn bit(self) -> u32 { | |
82 | 1 << (self as u8) | |
9c376795 FG |
83 | } |
84 | } |