1#[allow(unused)]
2use crate::Arg;
3#[allow(unused)]
4use crate::Command;
5
6#[derive(Default, Copy, Clone, Debug, PartialEq, Eq)]
7pub(crate) struct AppFlags(u32);
8
9impl 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}
26
27impl std::ops::BitOr for AppFlags {
28 type Output = Self;
29
30 fn bitor(mut self, rhs: Self) -> Self::Output {
31 self.insert(rhs);
32 self
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)]
43#[repr(u8)]
44pub(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,
60 ArgRequiredElseHelp,
61 NextLineHelp,
62 DisableColoredHelp,
63 DisableHelpFlag,
64 DisableHelpSubcommand,
65 DisableVersionFlag,
66 PropagateVersion,
67 Hidden,
68 HidePossibleValues,
69 HelpExpected,
70 NoBinaryName,
71 #[allow(dead_code)]
72 ColorAuto,
73 ColorAlways,
74 ColorNever,
75 Built,
76 BinNameBuilt,
77}
78
79impl AppSettings {
80 fn bit(self) -> u32 {
81 1 << (self as u8)
82 }
83}
84