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 FlattenHelp,
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
80impl AppSettings {
81 fn bit(self) -> u32 {
82 1 << (self as u8)
83 }
84}
85