diff options
Diffstat (limited to 'vendor/clap-3.2.20/src/util')
-rw-r--r-- | vendor/clap-3.2.20/src/util/color.rs | 62 | ||||
-rw-r--r-- | vendor/clap-3.2.20/src/util/fnv.rs | 46 | ||||
-rw-r--r-- | vendor/clap-3.2.20/src/util/graph.rs | 49 | ||||
-rw-r--r-- | vendor/clap-3.2.20/src/util/id.rs | 92 | ||||
-rw-r--r-- | vendor/clap-3.2.20/src/util/mod.rs | 40 | ||||
-rw-r--r-- | vendor/clap-3.2.20/src/util/str_to_bool.rs | 21 |
6 files changed, 0 insertions, 310 deletions
diff --git a/vendor/clap-3.2.20/src/util/color.rs b/vendor/clap-3.2.20/src/util/color.rs deleted file mode 100644 index 15c9901a0..000000000 --- a/vendor/clap-3.2.20/src/util/color.rs +++ /dev/null @@ -1,62 +0,0 @@ -/// Represents the color preferences for program output -#[derive(Debug, Copy, Clone, Eq, PartialEq)] -pub enum ColorChoice { - /// Enables colored output only when the output is going to a terminal or TTY. - /// - /// **NOTE:** This is the default behavior of `clap`. - /// - /// # Platform Specific - /// - /// This setting only applies to Unix, Linux, and macOS (i.e. non-Windows platforms). - /// - /// # Examples - /// - #[cfg_attr(not(feature = "color"), doc = " ```ignore")] - #[cfg_attr(feature = "color", doc = " ```no_run")] - /// # use clap::{Command, ColorChoice}; - /// Command::new("myprog") - /// .color(ColorChoice::Auto) - /// .get_matches(); - /// ``` - Auto, - - /// Enables colored output regardless of whether or not the output is going to a terminal/TTY. - /// - /// # Platform Specific - /// - /// This setting only applies to Unix, Linux, and macOS (i.e. non-Windows platforms). - /// - /// # Examples - /// - #[cfg_attr(not(feature = "color"), doc = " ```ignore")] - #[cfg_attr(feature = "color", doc = " ```no_run")] - /// # use clap::{Command, ColorChoice}; - /// Command::new("myprog") - /// .color(ColorChoice::Always) - /// .get_matches(); - /// ``` - Always, - - /// Disables colored output no matter if the output is going to a terminal/TTY, or not. - /// - /// # Platform Specific - /// - /// This setting only applies to Unix, Linux, and macOS (i.e. non-Windows platforms) - /// - /// # Examples - /// - #[cfg_attr(not(feature = "color"), doc = " ```ignore")] - #[cfg_attr(feature = "color", doc = " ```no_run")] - /// # use clap::{Command, ColorChoice}; - /// Command::new("myprog") - /// .color(ColorChoice::Never) - /// .get_matches(); - /// ``` - Never, -} - -impl Default for ColorChoice { - fn default() -> Self { - Self::Auto - } -} diff --git a/vendor/clap-3.2.20/src/util/fnv.rs b/vendor/clap-3.2.20/src/util/fnv.rs deleted file mode 100644 index 4602300a4..000000000 --- a/vendor/clap-3.2.20/src/util/fnv.rs +++ /dev/null @@ -1,46 +0,0 @@ -use std::{ - fmt::Display, - hash::{Hash, Hasher}, -}; - -const MAGIC_INIT: u64 = 0x811C_9DC5; - -// TODO: Docs -pub trait Key: Hash + Display { - fn key(&self) -> u64; -} - -impl<T> Key for T -where - T: Hash + Display, -{ - fn key(&self) -> u64 { - let mut hasher = FnvHasher::new(); - self.hash(&mut hasher); - hasher.finish() - } -} - -pub(crate) struct FnvHasher(u64); - -impl FnvHasher { - pub(crate) fn new() -> Self { - FnvHasher(MAGIC_INIT) - } -} - -impl Hasher for FnvHasher { - fn finish(&self) -> u64 { - self.0 - } - fn write(&mut self, bytes: &[u8]) { - let FnvHasher(mut hash) = *self; - - for byte in bytes.iter() { - hash ^= u64::from(*byte); - hash = hash.wrapping_mul(0x0100_0000_01b3); - } - - *self = FnvHasher(hash); - } -} diff --git a/vendor/clap-3.2.20/src/util/graph.rs b/vendor/clap-3.2.20/src/util/graph.rs deleted file mode 100644 index d646400b0..000000000 --- a/vendor/clap-3.2.20/src/util/graph.rs +++ /dev/null @@ -1,49 +0,0 @@ -#[derive(Debug)] -struct Child<T> { - id: T, - children: Vec<usize>, -} - -impl<T> Child<T> { - fn new(id: T) -> Self { - Child { - id, - children: vec![], - } - } -} - -#[derive(Debug)] -pub(crate) struct ChildGraph<T>(Vec<Child<T>>); - -impl<T> ChildGraph<T> -where - T: Sized + PartialEq + Clone, -{ - pub(crate) fn with_capacity(s: usize) -> Self { - ChildGraph(Vec::with_capacity(s)) - } - - pub(crate) fn insert(&mut self, req: T) -> usize { - self.0.iter().position(|e| e.id == req).unwrap_or_else(|| { - let idx = self.0.len(); - self.0.push(Child::new(req)); - idx - }) - } - - pub(crate) fn insert_child(&mut self, parent: usize, child: T) -> usize { - let c_idx = self.0.len(); - self.0.push(Child::new(child)); - self.0[parent].children.push(c_idx); - c_idx - } - - pub(crate) fn iter(&self) -> impl Iterator<Item = &T> { - self.0.iter().map(|r| &r.id) - } - - pub(crate) fn contains(&self, req: &T) -> bool { - self.0.iter().any(|r| r.id == *req) - } -} diff --git a/vendor/clap-3.2.20/src/util/id.rs b/vendor/clap-3.2.20/src/util/id.rs deleted file mode 100644 index 63a7e003e..000000000 --- a/vendor/clap-3.2.20/src/util/id.rs +++ /dev/null @@ -1,92 +0,0 @@ -use crate::util::fnv::Key; - -use std::{ - fmt::{Debug, Formatter, Result}, - hash::{Hash, Hasher}, - ops::Deref, -}; - -#[derive(Clone, Eq, Default)] -#[cfg_attr(not(debug_assertions), repr(transparent))] -pub(crate) struct Id { - #[cfg(debug_assertions)] - name: String, - id: u64, -} - -macro_rules! precomputed_hashes { - ($($fn_name:ident, $const:expr, $name:expr;)*) => { - impl Id { - $( - pub(crate) fn $fn_name() -> Self { - Id { - #[cfg(debug_assertions)] - name: $name.into(), - id: $const, - } - } - )* - } - }; -} - -// precompute some common values -precomputed_hashes! { - empty_hash, 0x1C9D_3ADB_639F_298E, ""; - help_hash, 0x5963_6393_CFFB_FE5F, "help"; - version_hash, 0x30FF_0B7C_4D07_9478, "version"; -} - -impl Id { - pub(crate) fn from_ref<T: Key>(val: T) -> Self { - Id { - #[cfg(debug_assertions)] - name: val.to_string(), - id: val.key(), - } - } -} - -impl Debug for Id { - fn fmt(&self, f: &mut Formatter) -> Result { - #[cfg(debug_assertions)] - write!(f, "{}", self.name)?; - #[cfg(not(debug_assertions))] - write!(f, "[hash: {:X}]", self.id)?; - - Ok(()) - } -} - -impl Deref for Id { - type Target = u64; - - fn deref(&self) -> &Self::Target { - &self.id - } -} - -impl<T: Key> From<T> for Id { - fn from(val: T) -> Self { - Id { - #[cfg(debug_assertions)] - name: val.to_string(), - id: val.key(), - } - } -} - -impl Hash for Id { - fn hash<H>(&self, state: &mut H) - where - H: Hasher, - { - self.id.hash(state) - } -} - -impl PartialEq for Id { - fn eq(&self, other: &Id) -> bool { - self.id == other.id - } -} diff --git a/vendor/clap-3.2.20/src/util/mod.rs b/vendor/clap-3.2.20/src/util/mod.rs deleted file mode 100644 index 8adc8db17..000000000 --- a/vendor/clap-3.2.20/src/util/mod.rs +++ /dev/null @@ -1,40 +0,0 @@ -#![allow(clippy::single_component_path_imports)] - -mod fnv; -mod graph; -mod id; -mod str_to_bool; - -pub use self::fnv::Key; - -pub(crate) use self::str_to_bool::str_to_bool; -pub(crate) use self::str_to_bool::FALSE_LITERALS; -pub(crate) use self::str_to_bool::TRUE_LITERALS; -pub(crate) use self::{graph::ChildGraph, id::Id}; - -pub(crate) mod color; - -pub(crate) const SUCCESS_CODE: i32 = 0; -// While sysexists.h defines EX_USAGE as 64, this doesn't seem to be used much in practice but -// instead 2 seems to be frequently used. -// Examples -// - GNU `ls` returns 2 -// - Python's `argparse` returns 2 -pub(crate) const USAGE_CODE: i32 = 2; - -pub(crate) fn safe_exit(code: i32) -> ! { - use std::io::Write; - - let _ = std::io::stdout().lock().flush(); - let _ = std::io::stderr().lock().flush(); - - std::process::exit(code) -} - -#[cfg(not(feature = "unicode"))] -pub(crate) fn eq_ignore_case(left: &str, right: &str) -> bool { - left.eq_ignore_ascii_case(right) -} - -#[cfg(feature = "unicode")] -pub(crate) use unicase::eq as eq_ignore_case; diff --git a/vendor/clap-3.2.20/src/util/str_to_bool.rs b/vendor/clap-3.2.20/src/util/str_to_bool.rs deleted file mode 100644 index 1fbdc7531..000000000 --- a/vendor/clap-3.2.20/src/util/str_to_bool.rs +++ /dev/null @@ -1,21 +0,0 @@ -/// True values are `y`, `yes`, `t`, `true`, `on`, and `1`. -pub(crate) const TRUE_LITERALS: [&str; 6] = ["y", "yes", "t", "true", "on", "1"]; - -/// False values are `n`, `no`, `f`, `false`, `off`, and `0`. -pub(crate) const FALSE_LITERALS: [&str; 6] = ["n", "no", "f", "false", "off", "0"]; - -/// Converts a string literal representation of truth to true or false. -/// -/// `false` values are `n`, `no`, `f`, `false`, `off`, and `0` (case insensitive). -/// -/// Any other value will be considered as `true`. -pub(crate) fn str_to_bool(val: impl AsRef<str>) -> Option<bool> { - let pat: &str = &val.as_ref().to_lowercase(); - if TRUE_LITERALS.contains(&pat) { - Some(true) - } else if FALSE_LITERALS.contains(&pat) { - Some(false) - } else { - None - } -} |