1 // Std 2 use std::ops::BitOr; 3 4 #[allow(unused)] 5 use crate::Arg; 6 #[allow(unused)] 7 use crate::Command; 8 9 // Third party 10 use bitflags::bitflags; 11 12 #[doc(hidden)] 13 #[derive(Debug, Copy, Clone, PartialEq, Eq)] 14 pub(crate) struct AppFlags(Flags); 15 16 impl Default for AppFlags { default() -> Self17 fn default() -> Self { 18 AppFlags(Flags::COLOR_AUTO) 19 } 20 } 21 22 /// Application level settings, which affect how [`Command`] operates 23 /// 24 /// **NOTE:** When these settings are used, they apply only to current command, and are *not* 25 /// propagated down or up through child or parent subcommands 26 /// 27 /// [`Command`]: crate::Command 28 #[derive(Debug, PartialEq, Copy, Clone)] 29 #[non_exhaustive] 30 pub(crate) enum AppSettings { 31 IgnoreErrors, 32 AllowHyphenValues, 33 AllowNegativeNumbers, 34 AllArgsOverrideSelf, 35 AllowMissingPositional, 36 TrailingVarArg, 37 DontDelimitTrailingValues, 38 InferLongArgs, 39 InferSubcommands, 40 SubcommandRequired, 41 AllowExternalSubcommands, 42 Multicall, 43 SubcommandsNegateReqs, 44 ArgsNegateSubcommands, 45 SubcommandPrecedenceOverArg, 46 ArgRequiredElseHelp, 47 NextLineHelp, 48 DisableColoredHelp, 49 DisableHelpFlag, 50 DisableHelpSubcommand, 51 DisableVersionFlag, 52 PropagateVersion, 53 Hidden, 54 HidePossibleValues, 55 HelpExpected, 56 NoBinaryName, 57 #[allow(dead_code)] 58 ColorAuto, 59 ColorAlways, 60 ColorNever, 61 Built, 62 BinNameBuilt, 63 } 64 65 bitflags! { 66 struct Flags: u64 { 67 const SC_NEGATE_REQS = 1; 68 const SC_REQUIRED = 1 << 1; 69 const ARG_REQUIRED_ELSE_HELP = 1 << 2; 70 const PROPAGATE_VERSION = 1 << 3; 71 const DISABLE_VERSION_FOR_SC = 1 << 4; 72 const WAIT_ON_ERROR = 1 << 6; 73 const DISABLE_VERSION_FLAG = 1 << 10; 74 const HIDDEN = 1 << 11; 75 const TRAILING_VARARG = 1 << 12; 76 const NO_BIN_NAME = 1 << 13; 77 const ALLOW_UNK_SC = 1 << 14; 78 const LEADING_HYPHEN = 1 << 16; 79 const NO_POS_VALUES = 1 << 17; 80 const NEXT_LINE_HELP = 1 << 18; 81 const DISABLE_COLORED_HELP = 1 << 20; 82 const COLOR_ALWAYS = 1 << 21; 83 const COLOR_AUTO = 1 << 22; 84 const COLOR_NEVER = 1 << 23; 85 const DONT_DELIM_TRAIL = 1 << 24; 86 const ALLOW_NEG_NUMS = 1 << 25; 87 const DISABLE_HELP_SC = 1 << 27; 88 const ARGS_NEGATE_SCS = 1 << 29; 89 const PROPAGATE_VALS_DOWN = 1 << 30; 90 const ALLOW_MISSING_POS = 1 << 31; 91 const TRAILING_VALUES = 1 << 32; 92 const BUILT = 1 << 33; 93 const BIN_NAME_BUILT = 1 << 34; 94 const VALID_ARG_FOUND = 1 << 35; 95 const INFER_SUBCOMMANDS = 1 << 36; 96 const CONTAINS_LAST = 1 << 37; 97 const ARGS_OVERRIDE_SELF = 1 << 38; 98 const HELP_REQUIRED = 1 << 39; 99 const SUBCOMMAND_PRECEDENCE_OVER_ARG = 1 << 40; 100 const DISABLE_HELP_FLAG = 1 << 41; 101 const INFER_LONG_ARGS = 1 << 43; 102 const IGNORE_ERRORS = 1 << 44; 103 const MULTICALL = 1 << 45; 104 const EXPAND_HELP_SUBCOMMAND_TREES = 1 << 46; 105 const NO_OP = 0; 106 } 107 } 108 109 impl_settings! { AppSettings, AppFlags, 110 ArgRequiredElseHelp 111 => Flags::ARG_REQUIRED_ELSE_HELP, 112 SubcommandPrecedenceOverArg 113 => Flags::SUBCOMMAND_PRECEDENCE_OVER_ARG, 114 ArgsNegateSubcommands 115 => Flags::ARGS_NEGATE_SCS, 116 AllowExternalSubcommands 117 => Flags::ALLOW_UNK_SC, 118 AllowHyphenValues 119 => Flags::LEADING_HYPHEN, 120 AllowNegativeNumbers 121 => Flags::ALLOW_NEG_NUMS, 122 AllowMissingPositional 123 => Flags::ALLOW_MISSING_POS, 124 ColorAlways 125 => Flags::COLOR_ALWAYS, 126 ColorAuto 127 => Flags::COLOR_AUTO, 128 ColorNever 129 => Flags::COLOR_NEVER, 130 DontDelimitTrailingValues 131 => Flags::DONT_DELIM_TRAIL, 132 DisableColoredHelp 133 => Flags::DISABLE_COLORED_HELP, 134 DisableHelpSubcommand 135 => Flags::DISABLE_HELP_SC, 136 DisableHelpFlag 137 => Flags::DISABLE_HELP_FLAG, 138 DisableVersionFlag 139 => Flags::DISABLE_VERSION_FLAG, 140 PropagateVersion 141 => Flags::PROPAGATE_VERSION, 142 HidePossibleValues 143 => Flags::NO_POS_VALUES, 144 HelpExpected 145 => Flags::HELP_REQUIRED, 146 Hidden 147 => Flags::HIDDEN, 148 Multicall 149 => Flags::MULTICALL, 150 NoBinaryName 151 => Flags::NO_BIN_NAME, 152 SubcommandsNegateReqs 153 => Flags::SC_NEGATE_REQS, 154 SubcommandRequired 155 => Flags::SC_REQUIRED, 156 TrailingVarArg 157 => Flags::TRAILING_VARARG, 158 NextLineHelp 159 => Flags::NEXT_LINE_HELP, 160 IgnoreErrors 161 => Flags::IGNORE_ERRORS, 162 Built 163 => Flags::BUILT, 164 BinNameBuilt 165 => Flags::BIN_NAME_BUILT, 166 InferSubcommands 167 => Flags::INFER_SUBCOMMANDS, 168 AllArgsOverrideSelf 169 => Flags::ARGS_OVERRIDE_SELF, 170 InferLongArgs 171 => Flags::INFER_LONG_ARGS 172 } 173