mirror of
https://github.com/XAMPPRocky/tokei
synced 2024-10-03 22:43:47 +00:00
Minimal version
This commit is contained in:
parent
b2790c4eee
commit
e4435402de
10
Cargo.lock
generated
10
Cargo.lock
generated
|
@ -12,7 +12,7 @@ dependencies = [
|
||||||
"serde_codegen 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde_codegen 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"serde_json 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde_json 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"serde_yaml 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde_yaml 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"toml 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)",
|
"toml 0.1.30 (git+https://github.com/alexcrichton/toml-rs)",
|
||||||
"walkdir 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
"walkdir 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dtoa"
|
name = "dtoa"
|
||||||
version = "0.2.1"
|
version = "0.2.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -208,7 +208,7 @@ name = "serde_json"
|
||||||
version = "0.8.0"
|
version = "0.8.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"dtoa 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"dtoa 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"itoa 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"itoa 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"num-traits 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",
|
"num-traits 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"serde 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -293,9 +293,9 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "toml"
|
name = "toml"
|
||||||
version = "0.1.30"
|
version = "0.1.30"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "git+https://github.com/alexcrichton/toml-rs#dd109bc9e9b8a6a5585e8bf1093ec84dcad61309"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde 0.7.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -55,7 +55,7 @@ version = "~0.4.0"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["serde"]
|
features = ["serde"]
|
||||||
optional = true
|
optional = true
|
||||||
version = "~0.1.30"
|
git = "https://github.com/alexcrichton/toml-rs"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
all = ["json", "cbor", "toml-io", "yaml"]
|
all = ["json", "cbor", "toml-io", "yaml"]
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
#[cfg(feature = "io")]
|
#[cfg(feature = "io")]
|
||||||
extern crate serde_codegen;
|
extern crate serde_codegen;
|
||||||
|
|
||||||
use std::env;
|
fn main() {
|
||||||
use std::path::Path;
|
|
||||||
|
|
||||||
pub fn main() {
|
|
||||||
expand();
|
expand();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(feature = "io")]
|
#[cfg(feature = "io")]
|
||||||
fn expand() {
|
fn expand() {
|
||||||
|
use std::env;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
let out_dir = env::var_os("OUT_DIR").unwrap();
|
let out_dir = env::var_os("OUT_DIR").unwrap();
|
||||||
|
|
||||||
let src = Path::new("src/lib/lib.rs.in");
|
let src = Path::new("src/lib/lib.rs.in");
|
||||||
|
|
|
@ -6,8 +6,8 @@ use sort::Sort::*;
|
||||||
use stats::Stats;
|
use stats::Stats;
|
||||||
|
|
||||||
/// Struct representing a single Language.
|
/// Struct representing a single Language.
|
||||||
#[cfg_attr(feature = "io", derive(Clone, Debug, Deserialize, Default, Eq, Ord, PartialEq, PartialOrd, Serialize))]
|
|
||||||
#[cfg(feature = "io")]
|
#[cfg(feature = "io")]
|
||||||
|
#[cfg_attr(feature = "io", derive(Clone, Debug, Deserialize, Default, Eq, Ord, PartialEq, PartialOrd, Serialize))]
|
||||||
pub struct Language {
|
pub struct Language {
|
||||||
/// Number of blank lines.
|
/// Number of blank lines.
|
||||||
pub blanks: usize,
|
pub blanks: usize,
|
||||||
|
|
|
@ -61,6 +61,8 @@ pub enum LanguageType {
|
||||||
FortranModern,
|
FortranModern,
|
||||||
/// Go
|
/// Go
|
||||||
Go,
|
Go,
|
||||||
|
/// Handlebars
|
||||||
|
Handlebars,
|
||||||
/// Haskell
|
/// Haskell
|
||||||
Haskell,
|
Haskell,
|
||||||
/// Html
|
/// Html
|
||||||
|
@ -198,6 +200,7 @@ impl LanguageType {
|
||||||
FortranLegacy => "FORTRAN Legacy",
|
FortranLegacy => "FORTRAN Legacy",
|
||||||
FortranModern => "FORTRAN Modern",
|
FortranModern => "FORTRAN Modern",
|
||||||
Go => "Go",
|
Go => "Go",
|
||||||
|
Handlebars => "Handlebars",
|
||||||
Haskell => "Haskell",
|
Haskell => "Haskell",
|
||||||
Html => "HTML",
|
Html => "HTML",
|
||||||
Idris => "Idris",
|
Idris => "Idris",
|
||||||
|
@ -283,6 +286,7 @@ impl LanguageType {
|
||||||
"f03" | "f08" | "f90" | "f95" => Some(FortranModern),
|
"f03" | "f08" | "f90" | "f95" => Some(FortranModern),
|
||||||
"go" => Some(Go),
|
"go" => Some(Go),
|
||||||
"h" => Some(CHeader),
|
"h" => Some(CHeader),
|
||||||
|
"hbs" | "handlebars" => Some(Handlebars),
|
||||||
"hh" | "hpp" | "hxx" => Some(CppHeader),
|
"hh" | "hpp" | "hxx" => Some(CppHeader),
|
||||||
"hs" => Some(Haskell),
|
"hs" => Some(Haskell),
|
||||||
"html" => Some(Html),
|
"html" => Some(Html),
|
||||||
|
@ -371,6 +375,7 @@ impl From<String> for LanguageType {
|
||||||
"FortranLegacy" => FortranLegacy,
|
"FortranLegacy" => FortranLegacy,
|
||||||
"FortranModern" => FortranModern,
|
"FortranModern" => FortranModern,
|
||||||
"Go" => Go,
|
"Go" => Go,
|
||||||
|
"Handlebars" => Handlebars,
|
||||||
"Haskell" => Haskell,
|
"Haskell" => Haskell,
|
||||||
"Html" => Html,
|
"Html" => Html,
|
||||||
"Idris" => Idris,
|
"Idris" => Idris,
|
||||||
|
|
|
@ -9,8 +9,8 @@ use std::io::Read;
|
||||||
use std::iter::IntoIterator;
|
use std::iter::IntoIterator;
|
||||||
use std::ops::{AddAssign, Deref, DerefMut};
|
use std::ops::{AddAssign, Deref, DerefMut};
|
||||||
|
|
||||||
#[cfg(feature = "cbor")]
|
// #[cfg(feature = "cbor")]
|
||||||
use serde_cbor;
|
// use serde_cbor;
|
||||||
#[cfg(feature = "json")]
|
#[cfg(feature = "json")]
|
||||||
use serde_json;
|
use serde_json;
|
||||||
#[cfg(feature = "yaml")]
|
#[cfg(feature = "yaml")]
|
||||||
|
@ -24,9 +24,11 @@ use super::{Language, LanguageType};
|
||||||
use super::LanguageType::*;
|
use super::LanguageType::*;
|
||||||
use stats::Stats;
|
use stats::Stats;
|
||||||
|
|
||||||
const CBOR_ERROR: &'static str = "Tokei was not compiled with the `cbor` flag.";
|
#[cfg(not(feature = "json"))]
|
||||||
const JSON_ERROR: &'static str = "Tokei was not compiled with the `json` flag.";
|
const JSON_ERROR: &'static str = "Tokei was not compiled with the `json` flag.";
|
||||||
|
#[cfg(not(feature = "toml-io"))]
|
||||||
const TOML_ERROR: &'static str = "Tokei was not compiled with the `toml-io` flag.";
|
const TOML_ERROR: &'static str = "Tokei was not compiled with the `toml-io` flag.";
|
||||||
|
#[cfg(not(feature = "yaml"))]
|
||||||
const YAML_ERROR: &'static str = "Tokei was not compiled with the `yaml` flag.";
|
const YAML_ERROR: &'static str = "Tokei was not compiled with the `yaml` flag.";
|
||||||
|
|
||||||
/// A collection of existing languages([_List of Languages_](https://github.com/Aaronepower/tokei#supported-languages))
|
/// A collection of existing languages([_List of Languages_](https://github.com/Aaronepower/tokei#supported-languages))
|
||||||
|
@ -37,34 +39,34 @@ pub struct Languages {
|
||||||
|
|
||||||
|
|
||||||
impl Languages {
|
impl Languages {
|
||||||
/// Creates a `Languages` struct from cbor.
|
// /// Creates a `Languages` struct from cbor.
|
||||||
///
|
// ///
|
||||||
/// ```
|
// /// ```
|
||||||
/// # extern crate tokei;
|
// /// # extern crate tokei;
|
||||||
/// # use tokei::*;
|
// /// # use tokei::*;
|
||||||
/// # extern crate rustc_serialize;
|
// /// # extern crate rustc_serialize;
|
||||||
/// # use rustc_serialize::hex::FromHex;
|
// /// # use rustc_serialize::hex::FromHex;
|
||||||
/// # fn main () {
|
// /// # fn main () {
|
||||||
/// let cbor = "a16452757374a666626c616e6b730564636f64650c68636f6d6d656e7473\
|
// /// let cbor = "a16452757374a666626c616e6b730564636f64650c68636f6d6d656e7473\
|
||||||
/// 0065737461747381a566626c616e6b730564636f64650c68636f6d6d656e74730065\
|
// /// 0065737461747381a566626c616e6b730564636f64650c68636f6d6d656e74730065\
|
||||||
/// 6c696e657311646e616d65722e5c7372635c6c69625c6275696c642e7273656c696e\
|
// /// 6c696e657311646e616d65722e5c7372635c6c69625c6275696c642e7273656c696e\
|
||||||
/// 6573116b746f74616c5f66696c657301";
|
// /// 6573116b746f74616c5f66696c657301";
|
||||||
///
|
// ///
|
||||||
/// let mut languages = Languages::from_cbor(&*cbor.from_hex().unwrap()).unwrap();
|
// /// let mut languages = Languages::from_cbor(&*cbor.from_hex().unwrap()).unwrap();
|
||||||
/// assert_eq!(12, languages.get_mut(&LanguageType::Rust).unwrap().code);
|
// /// assert_eq!(12, languages.get_mut(&LanguageType::Rust).unwrap().code);
|
||||||
/// # }
|
// /// # }
|
||||||
/// ```
|
// /// ```
|
||||||
#[cfg(feature = "cbor")]
|
// #[cfg(feature = "cbor")]
|
||||||
pub fn from_cbor<'a, I: Into<&'a [u8]>>(cbor: I) -> serde_cbor::Result<Self> {
|
// pub fn from_cbor<'a, I: Into<&'a [u8]>>(cbor: I) -> serde_cbor::Result<Self> {
|
||||||
let map = try!(serde_cbor::from_slice(cbor.into()));
|
// let map = try!(serde_cbor::from_slice(cbor.into()));
|
||||||
|
//
|
||||||
|
// Ok(Self::from_previous(map))
|
||||||
|
// }
|
||||||
|
|
||||||
Ok(Self::from_previous(map))
|
// #[cfg(not(feature = "cbor"))]
|
||||||
}
|
// pub fn from_cbor<'a, I: Into<&'a [u8]>>(cbor: I) -> ! {
|
||||||
|
// panic!(CBOR_ERROR)
|
||||||
#[cfg(not(feature = "cbor"))]
|
// }
|
||||||
pub fn from_cbor<'a, I: Into<&'a [u8]>>(cbor: I) -> ! {
|
|
||||||
panic!(CBOR_ERROR)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Creates a `Languages` struct from json.
|
/// Creates a `Languages` struct from json.
|
||||||
///
|
///
|
||||||
|
@ -98,6 +100,7 @@ impl Languages {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "json"))]
|
#[cfg(not(feature = "json"))]
|
||||||
|
#[allow(unused_variables)]
|
||||||
pub fn from_json<'a, I: Into<&'a [u8]>>(json: I) -> ! {
|
pub fn from_json<'a, I: Into<&'a [u8]>>(json: I) -> ! {
|
||||||
panic!(JSON_ERROR)
|
panic!(JSON_ERROR)
|
||||||
}
|
}
|
||||||
|
@ -134,10 +137,12 @@ impl Languages {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "yaml"))]
|
#[cfg(not(feature = "yaml"))]
|
||||||
|
#[allow(unused_variables)]
|
||||||
pub fn from_yaml<'a, I: Into<&'a [u8]>>(yaml: I) -> ! {
|
pub fn from_yaml<'a, I: Into<&'a [u8]>>(yaml: I) -> ! {
|
||||||
panic!(YAML_ERROR)
|
panic!(YAML_ERROR)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "io")]
|
||||||
fn from_previous(map: BTreeMap<LanguageType, Language>) -> Self {
|
fn from_previous(map: BTreeMap<LanguageType, Language>) -> Self {
|
||||||
let mut _self = Self::new();
|
let mut _self = Self::new();
|
||||||
|
|
||||||
|
@ -292,6 +297,7 @@ impl Languages {
|
||||||
FortranLegacy => Language::new_single(vec!["c","C","!","*"]),
|
FortranLegacy => Language::new_single(vec!["c","C","!","*"]),
|
||||||
FortranModern => Language::new_single(vec!["!"]),
|
FortranModern => Language::new_single(vec!["!"]),
|
||||||
Go => Language::new_c(),
|
Go => Language::new_c(),
|
||||||
|
Handlebars => Language::new_multi(vec![("<!--", "-->"), ("{{!", "}}")]),
|
||||||
Haskell => Language::new_single(vec!["--"]),
|
Haskell => Language::new_single(vec!["--"]),
|
||||||
Html => Language::new_html(),
|
Html => Language::new_html(),
|
||||||
Idris => Language::new(vec!["--"], vec![("{-", "-}")]),
|
Idris => Language::new(vec!["--"], vec![("{-", "-}")]),
|
||||||
|
@ -379,35 +385,36 @@ impl Languages {
|
||||||
map
|
map
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts `Languages` to CBOR.
|
// /// Converts `Languages` to CBOR.
|
||||||
///
|
// ///
|
||||||
/// ```no_run
|
// /// ```no_run
|
||||||
/// extern crate tokei;
|
// /// extern crate tokei;
|
||||||
/// # use tokei::*;
|
// /// # use tokei::*;
|
||||||
/// extern crate rustc_serialize;
|
// /// extern crate rustc_serialize;
|
||||||
/// use rustc_serialize::hex::ToHex;
|
// /// use rustc_serialize::hex::ToHex;
|
||||||
///
|
// ///
|
||||||
/// # fn main () {
|
// /// # fn main () {
|
||||||
/// let cbor = "a16452757374a666626c616e6b730564636f64650c68636f6d6d656e74730\
|
// /// let cbor = "a16452757374a666626c616e6b730564636f64650c68636f6d6d656e74730\
|
||||||
/// 065737461747381a566626c616e6b730564636f64650c68636f6d6d656e747300656c\
|
// /// 065737461747381a566626c616e6b730564636f64650c68636f6d6d656e747300656c\
|
||||||
/// 696e657311646e616d65722e5c7372635c6c69625c6275696c642e7273656c696e657\
|
// /// 696e657311646e616d65722e5c7372635c6c69625c6275696c642e7273656c696e657\
|
||||||
/// 3116b746f74616c5f66696c657301";
|
// /// 3116b746f74616c5f66696c657301";
|
||||||
///
|
// ///
|
||||||
/// let mut languages = Languages::new();
|
// /// let mut languages = Languages::new();
|
||||||
/// languages.get_statistics(&*vec!["src/lib/build.rs"], &*vec![".git"]);
|
// /// languages.get_statistics(&*vec!["src/lib/build.rs"], &*vec![".git"]);
|
||||||
///
|
// ///
|
||||||
/// assert_eq!(cbor, languages.to_cbor().unwrap().to_hex());
|
// /// assert_eq!(cbor, languages.to_cbor().unwrap().to_hex());
|
||||||
/// # }
|
// /// # }
|
||||||
/// ```
|
// /// ```
|
||||||
#[cfg(feature = "cbor")]
|
// #[cfg(feature = "cbor")]
|
||||||
pub fn to_cbor(&self) -> Result<Vec<u8>, serde_cbor::Error> {
|
// pub fn to_cbor(&self) -> Result<Vec<u8>, serde_cbor::Error> {
|
||||||
serde_cbor::to_vec(&self.remove_empty())
|
// serde_cbor::to_vec(&self.remove_empty())
|
||||||
}
|
// }
|
||||||
|
|
||||||
#[cfg(not(feature = "cbor"))]
|
// #[cfg(not(feature = "cbor"))]
|
||||||
pub fn to_cbor(&self) -> ! {
|
// #[allow(unused_variables)]
|
||||||
panic!(CBOR_ERROR)
|
// pub fn to_cbor(&self) -> ! {
|
||||||
}
|
// panic!(CBOR_ERROR)
|
||||||
|
// }
|
||||||
|
|
||||||
/// Converts `Languages` to JSON.
|
/// Converts `Languages` to JSON.
|
||||||
///
|
///
|
||||||
|
@ -442,6 +449,7 @@ impl Languages {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "json"))]
|
#[cfg(not(feature = "json"))]
|
||||||
|
#[allow(unused_variables)]
|
||||||
pub fn to_json(&self) -> ! {
|
pub fn to_json(&self) -> ! {
|
||||||
panic!(JSON_ERROR)
|
panic!(JSON_ERROR)
|
||||||
}
|
}
|
||||||
|
@ -452,6 +460,7 @@ impl Languages {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "toml-io"))]
|
#[cfg(not(feature = "toml-io"))]
|
||||||
|
#[allow(unused_variables)]
|
||||||
pub fn to_toml(&self) -> ! {
|
pub fn to_toml(&self) -> ! {
|
||||||
panic!(TOML_ERROR)
|
panic!(TOML_ERROR)
|
||||||
}
|
}
|
||||||
|
@ -484,6 +493,7 @@ impl Languages {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "yaml"))]
|
#[cfg(not(feature = "yaml"))]
|
||||||
|
#[allow(unused_variables)]
|
||||||
pub fn to_yaml(&self) -> ! {
|
pub fn to_yaml(&self) -> ! {
|
||||||
panic!(YAML_ERROR)
|
panic!(YAML_ERROR)
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,13 +52,13 @@ extern crate glob;
|
||||||
extern crate rayon;
|
extern crate rayon;
|
||||||
#[cfg(feature = "io")]
|
#[cfg(feature = "io")]
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
#[cfg(feature = "cbor")]
|
// #[cfg(feature = "cbor")]
|
||||||
extern crate serde_cbor;
|
// extern crate serde_cbor;
|
||||||
#[cfg(feature = "json")]
|
#[cfg(feature = "json")]
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
#[cfg(feature = "yaml")]
|
#[cfg(feature = "yaml")]
|
||||||
extern crate serde_yaml;
|
extern crate serde_yaml;
|
||||||
#[cfg(feature = "toml")]
|
#[cfg(feature = "toml-io")]
|
||||||
extern crate toml;
|
extern crate toml;
|
||||||
extern crate walkdir;
|
extern crate walkdir;
|
||||||
|
|
||||||
|
|
45
src/main.rs
45
src/main.rs
|
@ -4,29 +4,28 @@
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate clap;
|
extern crate clap;
|
||||||
#[cfg(feature = "cbor")]
|
// #[cfg(feature = "cbor")]
|
||||||
extern crate serde_cbor;
|
// extern crate serde_cbor;
|
||||||
#[cfg(feature = "json")]
|
#[cfg(feature = "json")]
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
#[cfg(feature = "yaml")]
|
#[cfg(feature = "yaml")]
|
||||||
extern crate serde_yaml;
|
extern crate serde_yaml;
|
||||||
#[cfg(feature = "toml-io")]
|
#[cfg(feature = "toml-io")]
|
||||||
extern crate toml;
|
extern crate toml;
|
||||||
#[cfg(feature = "cbor")]
|
// #[cfg(feature = "cbor")]
|
||||||
extern crate rustc_serialize;
|
// extern crate rustc_serialize;
|
||||||
extern crate tokei;
|
extern crate tokei;
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
#[cfg(feature = "io")]
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::fs::File;
|
|
||||||
use std::io::Read;
|
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use std::sync::mpsc::channel;
|
use std::sync::mpsc::channel;
|
||||||
|
|
||||||
use clap::App;
|
use clap::App;
|
||||||
#[cfg(feature = "cbor")]
|
// #[cfg(feature = "cbor")]
|
||||||
use rustc_serialize::hex::FromHex;
|
// use rustc_serialize::hex::FromHex;
|
||||||
|
|
||||||
use tokei::{Languages, Language, LanguageType};
|
use tokei::{Languages, Language, LanguageType};
|
||||||
use tokei::Sort::*;
|
use tokei::Sort::*;
|
||||||
|
@ -37,6 +36,7 @@ const COMMENTS: &'static str = "comments";
|
||||||
const CODE: &'static str = "code";
|
const CODE: &'static str = "code";
|
||||||
const FILES: &'static str = "files";
|
const FILES: &'static str = "files";
|
||||||
const LINES: &'static str = "lines";
|
const LINES: &'static str = "lines";
|
||||||
|
#[cfg(not(feature = "io"))]
|
||||||
const OUTPUT_ERROR: &'static str = "This version of tokei was compiled without any serialization
|
const OUTPUT_ERROR: &'static str = "This version of tokei was compiled without any serialization
|
||||||
formats, to enable serialization, reinstall tokei with the features flag.
|
formats, to enable serialization, reinstall tokei with the features flag.
|
||||||
|
|
||||||
|
@ -46,16 +46,13 @@ const OUTPUT_ERROR: &'static str = "This version of tokei was compiled without a
|
||||||
JSON:
|
JSON:
|
||||||
cargo install tokei --features json
|
cargo install tokei --features json
|
||||||
|
|
||||||
CBOR:
|
|
||||||
cargo install tokei --features cbor
|
|
||||||
|
|
||||||
TOML:
|
TOML:
|
||||||
cargo install tokei --features toml
|
cargo install tokei --features toml
|
||||||
|
|
||||||
YAML:
|
YAML:
|
||||||
cargo install toke --features yaml
|
cargo install toke --features yaml
|
||||||
|
|
||||||
You can also have any mix of json cbor toml, or yaml.
|
You can also have any mix of json, toml, or yaml.
|
||||||
";
|
";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -159,7 +156,7 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(format) = output_option {
|
if let Some(format) = output_option {
|
||||||
match_output(&format);
|
match_output(&format, &languages);
|
||||||
} else if let Some(sort_category) = sort_option {
|
} else if let Some(sort_category) = sort_option {
|
||||||
|
|
||||||
for (_, ref mut language) in &mut languages {
|
for (_, ref mut language) in &mut languages {
|
||||||
|
@ -217,7 +214,10 @@ fn main() {
|
||||||
|
|
||||||
|
|
||||||
#[cfg(feature = "io")]
|
#[cfg(feature = "io")]
|
||||||
fn add_input(input: &str, map: &mut BTreeMap<LanguageType, Language>) {
|
fn add_input(input: &str, languages: &mut Languages) {
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::Read;
|
||||||
|
|
||||||
let map = match File::open(input) {
|
let map = match File::open(input) {
|
||||||
Ok(mut file) => {
|
Ok(mut file) => {
|
||||||
let contents = {
|
let contents = {
|
||||||
|
@ -242,13 +242,14 @@ fn add_input(input: &str, map: &mut BTreeMap<LanguageType, Language>) {
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(map) = map {
|
if let Some(map) = map {
|
||||||
languages += map;
|
*languages += map;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "io"))]
|
#[cfg(not(feature = "io"))]
|
||||||
fn add_input(input: &str, map: &mut BTreeMap<LanguageType, Language>) -> ! {
|
#[allow(unused_variables)]
|
||||||
|
fn add_input(input: &str, map: &mut Languages) -> ! {
|
||||||
panic!(OUTPUT_ERROR)
|
panic!(OUTPUT_ERROR)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,12 +264,6 @@ pub fn convert_input(contents: String) -> Option<BTreeMap<LanguageType, Language
|
||||||
Some(result)
|
Some(result)
|
||||||
} else if let Ok(result) = serde_yaml::from_str(&*contents) {
|
} else if let Ok(result) = serde_yaml::from_str(&*contents) {
|
||||||
Some(result)
|
Some(result)
|
||||||
} else if let Ok(hex) = contents.from_hex() {
|
|
||||||
if let Ok(result) = serde_cbor::from_slice(&*hex) {
|
|
||||||
Some(result)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
} else if let Some(result) = toml::decode_str(&*contents) {
|
} else if let Some(result) = toml::decode_str(&*contents) {
|
||||||
Some(result)
|
Some(result)
|
||||||
} else {
|
} else {
|
||||||
|
@ -277,7 +272,7 @@ pub fn convert_input(contents: String) -> Option<BTreeMap<LanguageType, Language
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "io")]
|
#[cfg(feature = "io")]
|
||||||
fn match_output(format: &str) {
|
fn match_output(format: &str, languages: &Languages) {
|
||||||
match format {
|
match format {
|
||||||
"cbor" => {
|
"cbor" => {
|
||||||
// let cbor: Vec<u8> = languages.to_cbor().unwrap();
|
// let cbor: Vec<u8> = languages.to_cbor().unwrap();
|
||||||
|
@ -294,12 +289,14 @@ fn match_output(format: &str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "io"))]
|
#[cfg(not(feature = "io"))]
|
||||||
fn match_output(format: &str) -> ! {
|
#[allow(unused_variables)]
|
||||||
|
fn match_output(format: &str, languages: &Languages) -> ! {
|
||||||
panic!(OUTPUT_ERROR)
|
panic!(OUTPUT_ERROR)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(not(feature = "io"))]
|
#[cfg(not(feature = "io"))]
|
||||||
|
#[allow(unused_variables)]
|
||||||
pub fn convert_input(contents: String) -> ! {
|
pub fn convert_input(contents: String) -> ! {
|
||||||
panic!(OUTPUT_ERROR);
|
panic!(OUTPUT_ERROR);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue