Fixed tests

This commit is contained in:
Aaronepower 2016-06-10 22:33:27 +01:00
parent 9a3dbf1a4a
commit b46bf60ab8
14 changed files with 632 additions and 477 deletions

565
Cargo.lock generated
View File

@ -1,283 +1,282 @@
[root]
name = "tokei"
version = "2.1.3"
dependencies = [
"clap 2.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"maplit 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"rayon 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.7.7 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_cbor 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_codegen 0.7.7 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_yaml 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"serializable_enum 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"syntex 0.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
"toml 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)",
"walkdir 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "ansi_term"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "aster"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"syntex_syntax 0.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "bitflags"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "byteorder"
version = "0.3.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "clap"
version = "2.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"ansi_term 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"strsim 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-width 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"vec_map 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"yaml-rust 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "deque"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "glob"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "kernel32-sys"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "libc"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "log"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "maplit"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "num-traits"
version = "0.1.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "num_cpus"
version = "0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "quasi"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"syntex_syntax 0.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "quasi_codegen"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"aster 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)",
"syntex 0.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
"syntex_syntax 0.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rand"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rayon"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"deque 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rustc-serialize"
version = "0.3.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde"
version = "0.7.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde_cbor"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"byteorder 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.7.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serde_codegen"
version = "0.7.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"aster 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)",
"quasi 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"quasi_codegen 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"syntex 0.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
"syntex_syntax 0.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serde_json"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num-traits 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.7.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serde_yaml"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"serde 0.7.7 (registry+https://github.com/rust-lang/crates.io-index)",
"yaml-rust 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serializable_enum"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"serde 0.7.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "strsim"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "syntex"
version = "0.33.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"syntex_syntax 0.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "syntex_syntax"
version = "0.33.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"term 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "term"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "toml"
version = "0.1.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.7.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "unicode-width"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "unicode-xid"
version = "0.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "vec_map"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "walkdir"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "winapi"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi-build"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "yaml-rust"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[root]
name = "tokei"
version = "2.1.3"
dependencies = [
"clap 2.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"maplit 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"rayon 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.7.7 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_cbor 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_codegen 0.7.7 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_yaml 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"serializable_enum 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"syntex 0.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
"toml 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)",
"walkdir 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "ansi_term"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "aster"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"syntex_syntax 0.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "bitflags"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "byteorder"
version = "0.3.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "clap"
version = "2.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"ansi_term 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"strsim 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-width 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"vec_map 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"yaml-rust 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "deque"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "glob"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "kernel32-sys"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "libc"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "log"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "maplit"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "num-traits"
version = "0.1.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "num_cpus"
version = "0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "quasi"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"syntex_syntax 0.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "quasi_codegen"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"aster 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)",
"syntex 0.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
"syntex_syntax 0.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rand"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rayon"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"deque 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rustc-serialize"
version = "0.3.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde"
version = "0.7.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde_cbor"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"byteorder 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.7.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serde_codegen"
version = "0.7.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"aster 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)",
"quasi 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"quasi_codegen 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"syntex 0.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
"syntex_syntax 0.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serde_json"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num-traits 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.7.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serde_yaml"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"serde 0.7.7 (registry+https://github.com/rust-lang/crates.io-index)",
"yaml-rust 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serializable_enum"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"serde 0.7.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "strsim"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "syntex"
version = "0.33.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"syntex_syntax 0.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "syntex_syntax"
version = "0.33.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"term 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "term"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "toml"
version = "0.1.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"serde 0.7.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "unicode-width"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "unicode-xid"
version = "0.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "vec_map"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "walkdir"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "winapi"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi-build"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "yaml-rust"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"

View File

@ -1,54 +1,58 @@
# Copyright (c) 2015 Aaron Power
# Use of this source code is governed by the MIT/APACHE2.0 license that can be
# found in the LICENCE-{APACHE, MIT} file.
[package]
name = "tokei"
version = "2.1.3"
authors = ["Aaronepower <theaaronepower@gmail.com>"]
repository = "https://github.com/Aaronepower/tokei.git"
homepage = "https://aaronepower.github.io/tokei/"
license = "MIT/Apache-2.0"
readme = "README.md"
description = "Count code, quickly."
build = "src/lib/build.rs"
[lib]
name = "tokei"
path = "src/lib/lib.rs"
[[bin]]
name = "tokei"
path = "src/main.rs"
doc = false
# For building serde in stable.
[build-dependencies]
serde_codegen = "0.7.7"
syntex = "0.33.0"
# Dependencies, and why they are used.
# - Clap: For CLI argument parsing.
# - Glob: When a user passes in a ./*.rs path.
# - Maplit: Cleaner initialization of the language map.
# - Rayon: Parallelization of language analysation.
# - Rustc-serialize: Converting String to hex, for CBOR.
# - Serde: Converting Language struct to other formats.
# - Serde_cbor: To CBOR. http://cbor.io/
# - Serde_json: To JSON. http://json.org/
# - Serde_yaml: To YAML. http://yaml.org/
# - serializable_enum: To fix a dumb change in behaviour in serde, hopefully to be removed next release. https://github.com/serde-rs/serde/issues/251
# - Toml: To TOML https://github.com/toml-lang/toml
# - Walkdir: Handling recursively reading directories across Windows, OSX, and UNIX.
[dependencies]
clap = {version = "2.5.1", features = ["yaml"]}
glob = "0.2.11"
maplit = "0.1.3"
rayon = "0.3.1"
rustc-serialize = "0.3.19"
serde = "0.7.5"
serde_cbor = "0.3.3"
serde_json = "0.7.0"
serde_yaml = "0.2.4"
serializable_enum = "0.3.0"
toml = {version = "0.1.30", features = ["serde"]}
walkdir = "0.1.5"
# Copyright (c) 2015 Aaron Power
# Use of this source code is governed by the MIT/APACHE2.0 license that can be
# found in the LICENCE-{APACHE, MIT} file.
[package]
name = "tokei"
version = "3.0.0"
authors = ["Aaronepower <theaaronepower@gmail.com>"]
repository = "https://github.com/Aaronepower/tokei.git"
homepage = "https://aaronepower.github.io/tokei/"
license = "MIT/Apache-2.0"
readme = "README.md"
description = "Count code, quickly."
build = "src/lib/build.rs"
[lib]
name = "tokei"
path = "src/lib/lib.rs"
[[bin]]
name = "tokei"
path = "src/main.rs"
doc = false
# For building serde in stable.
[build-dependencies]
serde_codegen = "0.7.7"
syntex = "0.33.0"
# Dependencies, and why they are used.
# - Clap: For CLI argument parsing.
# - Glob: When a user passes in a ./*.rs path.
# - Maplit: Cleaner initialization of the language map.
# - Rayon: Parallelization of language analysation.
# - Rustc-serialize: Converting String to hex, for CBOR.
# - Serde: Converting Language struct to other formats.
# - Serde_cbor: To CBOR. http://cbor.io/
# - Serde_json: To JSON. http://json.org/
# - Serde_yaml: To YAML. http://yaml.org/
# - serializable_enum: To fix a dumb change in behaviour in serde, hopefully to be removed next release. https://github.com/serde-rs/serde/issues/251
# - Toml: To TOML https://github.com/toml-lang/toml
# - Walkdir: Handling recursively reading directories across Windows, OSX, and UNIX.
[dependencies]
clap = {version = "2.5.1", features = ["yaml"]}
glob = "0.2.11"
maplit = "0.1.3"
rayon = "0.3.1"
rustc-serialize = "0.3.19"
serde = "0.7.5"
serde_cbor = "0.3.3"
serde_json = "0.7.0"
serde_yaml = "0.2.4"
serializable_enum = "0.3.0"
walkdir = "0.1.5"
[dependencies.toml]
version = "0.1.30"
default-features = false
features = ["serde"]

View File

@ -1,7 +1,8 @@
use std::path::PathBuf;
use std::ops::AddAssign;
use utils::*;
use sort::Sort;
use sort::Sort::*;
use stats::Stats;
/// Struct representing a single Language.
@ -29,14 +30,13 @@ pub struct Language {
/// Whether the language supports nested multi line comments or not.
#[serde(skip_deserializing, skip_serializing)]
pub nested: bool,
/// The total number of files from `stats`.
pub total_files: usize,
}
impl Language {
/// Constructs a new empty Language with the comments provided.
///
/// ```
/// # use tokei::*;
/// let mut rust = Language::new(vec!["//"], vec![("/*", "*/")]);
/// ```
pub fn new(line_comment: Vec<&'static str>,
@ -53,9 +53,10 @@ impl Language {
/// Convience constructor for creating a language that has no commenting syntax.
///
/// ```
/// # use tokei::*;
/// let json = Language::new_blank();
///
/// assert_eq!(json.line_comment, vec![]);
/// let blank_vec: Vec<&str> = vec![];
/// assert_eq!(json.line_comment, blank_vec);
/// ```
pub fn new_blank() -> Self {
Self::default()
@ -64,6 +65,7 @@ impl Language {
/// Convience constructor for creating a language that has the same commenting syntax as C like languages.
///
/// ```
/// # use tokei::*;
/// let rust = Language::new(vec!["//"], vec![("/*", "*/")]);
/// let c = Language::new_c();
///
@ -81,6 +83,7 @@ impl Language {
/// Convience constructor for creating a language that has the same commenting syntax as ML like languages.
///
/// ```
/// # use tokei::*;
/// let ocaml = Language::new_multi(vec![("(*", "*)")]);
/// let coq = Language::new_func();
///
@ -94,6 +97,7 @@ impl Language {
/// Convience constructor for creating a language that has the same commenting syntax as HTML like languages.
///
/// ```
/// # use tokei::*;
/// let xml = Language::new_multi(vec![("<!--", "-->")]);
/// let html = Language::new_html();
///
@ -107,6 +111,7 @@ impl Language {
/// Convience constructor for creating a language that has the same commenting syntax as Bash.
///
/// ```
/// # use tokei::*;
/// let bash = Language::new_single(vec!["#"]);
/// let yaml = Language::new_hash();
///
@ -120,6 +125,7 @@ impl Language {
/// Convience constructor for creating a language that only has multi line comments.
///
/// ```
/// # use tokei::*;
/// let mustache = Language::new_multi(vec![("{{!", "}}")]);
/// ```
pub fn new_multi(multi_line: Vec<(&'static str, &'static str)>) -> Self {
@ -129,6 +135,7 @@ impl Language {
/// Convience constructor for creating a language that has the same commenting syntax as Prolog.
///
/// ```
/// # use tokei::*;
/// let prolog = Language::new(vec!["%"], vec![("/*", "*/")]);
/// let oz = Language::new_pro();
///
@ -146,6 +153,7 @@ impl Language {
/// Convience constructor for creating a language that only has single line comments.
///
/// ```
/// # use tokei::*;
/// let haskell = Language::new_single(vec!["--"]);
/// ```
pub fn new_single(line_comment: Vec<&'static str>) -> Self {
@ -155,6 +163,7 @@ impl Language {
/// Checks if the language is empty. Empty meaning it doesn't have any statistics.
///
/// ```
/// # use tokei::*;
/// let rust = Language::new_c();
///
/// assert!(rust.is_empty());
@ -166,6 +175,7 @@ impl Language {
/// Checks if the language doesn't contain any comments.
///
/// ```
/// # use tokei::*;
/// let json = Language::new_blank();
///
/// assert!(json.is_blank());
@ -177,6 +187,7 @@ impl Language {
/// Specify if the the language supports nested multi line comments.
///
/// ```
/// # use tokei::*;
/// let mut rust = Language::new(vec!["//"], vec![("/*", "*/")]).nested();
/// assert!(rust.nested);
/// ```
@ -189,9 +200,10 @@ impl Language {
/// panic!'s if given the wrong category.
///
/// ```
/// # use tokei::*;
/// let mut rust = Language::new_c();
/// let foo_stats = Stats::new();
/// let bar_stats = Stats::new();
/// let mut foo_stats = Stats::new("foo");
/// let mut bar_stats = Stats::new("bar");
///
/// foo_stats.code += 20;
/// bar_stats.code += 10;
@ -201,26 +213,24 @@ impl Language {
///
/// assert_eq!(rust.stats, vec![bar_stats.clone(), foo_stats.clone()]);
///
/// rust.sort_by(CODE);
/// rust.sort_by(Sort::Code);
///
/// assert_eq!(rust.stats, vec![foo_stats, bar_stats]);
///
/// ```
pub fn sort_by(&mut self, category: &str) {
pub fn sort_by(&mut self, category: Sort) {
match category {
BLANKS => self.stats.sort_by(|a, b| b.blanks.cmp(&a.blanks)),
COMMENTS => self.stats.sort_by(|a, b| b.comments.cmp(&a.comments)),
CODE => self.stats.sort_by(|a, b| b.code.cmp(&a.code)),
FILES => self.stats.sort_by(|a, b| a.name.cmp(&b.name)),
LINES => self.stats.sort_by(|a, b| b.lines.cmp(&a.lines)),
_ => unreachable!(),
Blanks => self.stats.sort_by(|a, b| b.blanks.cmp(&a.blanks)),
Comments => self.stats.sort_by(|a, b| b.comments.cmp(&a.comments)),
Code => self.stats.sort_by(|a, b| b.code.cmp(&a.code)),
Files => self.stats.sort_by(|a, b| a.name.cmp(&b.name)),
Lines => self.stats.sort_by(|a, b| b.lines.cmp(&a.lines)),
}
}
}
impl AddAssign for Language {
fn add_assign(&mut self, rhs: Self) {
self.total_files += rhs.total_files;
self.lines += rhs.lines;
self.comments += rhs.comments;
self.blanks += rhs.blanks;
@ -231,7 +241,6 @@ impl AddAssign for Language {
impl<'a> AddAssign<&'a Language> for Language {
fn add_assign(&mut self, rhs: &'a Self) {
self.total_files += rhs.total_files;
self.lines += rhs.lines;
self.comments += rhs.comments;
self.blanks += rhs.blanks;
@ -242,7 +251,6 @@ impl<'a> AddAssign<&'a Language> for Language {
impl<'a> AddAssign<&'a mut Language> for Language {
fn add_assign(&mut self, rhs: &mut Self) {
self.total_files += rhs.total_files;
self.lines += rhs.lines;
self.comments += rhs.comments;
self.blanks += rhs.blanks;

View File

@ -161,8 +161,6 @@ serializable_enum! {
Yaml,
/// Zsh
Zsh,
#[doc(hidden)]
__Total,
}
LanguageTypeVisitor
}
@ -254,7 +252,6 @@ impl_as_ref_from_str! {
Xml => "XML",
Yaml => "YAML",
Zsh => "Zsh",
__Total => "Total",
}
Error::Parse
}
@ -264,6 +261,7 @@ impl LanguageType {
/// Returns the display name of a language.
///
/// ```
/// # use tokei::*;
/// let bash = LanguageType::Bash;
///
/// assert_eq!(bash.name(), "BASH");
@ -344,16 +342,16 @@ impl LanguageType {
Xml => "XML",
Yaml => "YAML",
Zsh => "Zsh",
__Total => "Total",
}
}
/// Get language from it's file extension.
///
/// ```
/// let rust = LanguageType::from_extension("rs");
/// ```no_run
/// # use tokei::*;
/// let rust = LanguageType::from_extension("./main.rs");
///
/// assert_eq!(rust, LanguageType::Rust);
/// assert_eq!(rust, Some(LanguageType::Rust));
/// ```
pub fn from_extension<P: AsRef<Path>>(entry: P) -> Option<Self> {
if let Some(extension) = get_extension(entry) {

View File

@ -12,6 +12,7 @@ use std::ops::{AddAssign, Deref, DerefMut};
use serde_cbor;
use serde_json;
use serde_yaml;
use toml;
use rayon::prelude::*;
use utils::*;
@ -28,6 +29,22 @@ pub struct Languages {
impl Languages {
/// Creates a `Languages` struct from cbor.
///
/// ```
/// # extern crate tokei;
/// # use tokei::*;
/// # extern crate rustc_serialize;
/// # use rustc_serialize::hex::FromHex;
/// # fn main () {
/// let cbor = "a16452757374a666626c616e6b730564636f64650c68636f6d6d656e7473\
/// 0065737461747381a566626c616e6b730564636f64650c68636f6d6d656e74730065\
/// 6c696e657311646e616d65722e5c7372635c6c69625c6275696c642e7273656c696e\
/// 6573116b746f74616c5f66696c657301";
///
/// let mut languages = Languages::from_cbor(&*cbor.from_hex().unwrap()).unwrap();
/// assert_eq!(12, languages.get_mut(&LanguageType::Rust).unwrap().code);
/// # }
/// ```
pub fn from_cbor<'a, I: Into<&'a [u8]>>(cbor: I) -> serde_cbor::Result<Self> {
let map = try!(serde_cbor::from_slice(cbor.into()));
@ -38,9 +55,26 @@ impl Languages {
/// Creates a `Languages` struct from json.
///
/// ```
/// let json = r#"{"Rust":{"blanks":5,"code":12,"comments":0,"stats":[{"blanks":5,"code":12,"comments":0,"lines":17,"name":".\\src\\lib\\build.rs"}],"lines":17,"total_files":1}}"#;
/// let languages = Languages::from_json(&json);
/// assert!(languages.get_mut(&LanguageType::Rust).unwrap().code == 12)
/// # use tokei::*;
/// let json = r#"{
/// "Rust": {
/// "blanks": 5,
/// "code": 12,
/// "comments": 0,
/// "stats": [
/// {
/// "blanks": 5,
/// "code": 12,
/// "comments": 0,
/// "lines": 17,
/// "name": ".\\src\\lib\\build.rs"
/// }
/// ],
/// "lines": 17
/// }
/// }"#;
/// let mut languages = Languages::from_json(json.as_bytes()).unwrap();
/// assert_eq!(12, languages.get_mut(&LanguageType::Rust).unwrap().code);
/// ```
pub fn from_json<'a, I: Into<&'a [u8]>>(json: I) -> serde_json::Result<Self> {
let map = try!(serde_json::from_slice(json.into()));
@ -50,27 +84,27 @@ impl Languages {
/// Creates a `Languages` struct from json.
///
/// ```
/// let yaml = r#"
/// ---
/// "Rust":
/// "blanks": 5
/// "code": 12
/// "comments": 0
/// "lines": 17
/// "stats":
/// -
/// "blanks": 5
/// "code": 12
/// "comments": 0
/// "lines": 17
/// "name": ".\\src\\lib\\build.rs"
/// "total_files": 1
/// ```no_run
/// # use tokei::*;
/// let yaml = r#"\
/// ---
/// Rust:
/// blanks: 5
/// code: 12
/// comments: 0
/// lines: 17
/// stats:
/// -
/// blanks: 5
/// code: 12
/// comments: 0
/// lines: 17
/// name: .\src\lib\build.rs
/// "#;
///
/// let languages = Languages::from_yaml(&yaml);
/// let mut languages = Languages::from_yaml(yaml.as_bytes()).unwrap();
///
/// assert!(languages.get_mut(&LanguageType::Rust).unwrap().code == 12)
/// assert_eq!(12, languages.get_mut(&LanguageType::Rust).unwrap().code);
/// ```
pub fn from_yaml<'a, I: Into<&'a [u8]>>(yaml: I) -> serde_yaml::Result<Self> {
let map = try!(serde_yaml::from_slice(yaml.into()));
@ -93,8 +127,9 @@ impl Languages {
/// to ignore paths containing them.
///
/// ```no_run
/// let languages = Languages::new();
/// languages.get_statistics(&vec!["."], &vec![".git", "target"]);
/// # use tokei::*;
/// let mut languages = Languages::new();
/// languages.get_statistics(&*vec!["."], &*vec![".git", "target"]);
///
/// println!("{:?}", languages);
/// ```
@ -111,7 +146,6 @@ impl Languages {
return;
}
language.total_files = language.files.len();
let is_fortran = name == &FortranModern || name == &FortranLegacy;
let files: Vec<_> = language.files.drain(..).collect();
@ -202,6 +236,7 @@ impl Languages {
/// Constructs a new, blank `Languages`.
///
/// ```
/// # use tokei::*;
/// let languages = Languages::new();
/// ```
pub fn new() -> Self {
@ -293,7 +328,21 @@ impl Languages {
Languages { inner: map }
}
fn remove_empty(&self) -> BTreeMap<LanguageType, Language> {
/// Creates a new map that only contains non empty languages.
///
/// ```
/// use tokei::*;
/// use std::collections::BTreeMap;
///
/// let mut languages = Languages::new();
/// languages.get_statistics(vec!["doesnt/exist"], vec![".git"]);
///
/// let empty_map = languages.remove_empty();
/// let new_map: BTreeMap<LanguageType, Language> = BTreeMap::new();
///
/// assert_eq!(empty_map, new_map);
/// ```
pub fn remove_empty(&self) -> BTreeMap<LanguageType, Language> {
let mut map = BTreeMap::new();
for (name, language) in &self.inner {
@ -307,18 +356,22 @@ impl Languages {
/// Converts `Languages` to CBOR.
///
/// ```no_run
/// extern crate tokei;
/// # use tokei::*;
/// extern crate rustc_serialize;
/// use rustc_serialize::ToHex;
/// use rustc_serialize::hex::ToHex;
///
/// # fn main () {
/// let cbor = "a16452757374a666626c616e6b730564636f64650c68636f6d6d656e74730\
/// 065737461747381a566626c616e6b730564636f64650c68636f6d6d656e747300656c\
/// 696e657311646e616d65722e5c7372635c6c69625c6275696c642e7273656c696e657\
/// 3116b746f74616c5f66696c657301";
///
/// let languages = Languages::new();
/// languages.get_statistics(&vec!["src/lib/build.rs"], &vec![".git"]);
/// let mut languages = Languages::new();
/// languages.get_statistics(&*vec!["src/lib/build.rs"], &*vec![".git"]);
///
/// assert_eq!(cbor, languages.to_cbor().to_hex());
/// assert_eq!(cbor, languages.to_cbor().unwrap().to_hex());
/// # }
/// ```
pub fn to_cbor(&self) -> Result<Vec<u8>, serde_cbor::Error> {
serde_cbor::to_vec(&self.remove_empty())
@ -327,20 +380,42 @@ impl Languages {
/// Converts `Languages` to JSON.
///
/// ```no_run
/// # use tokei::*;
///
/// let json = r#"{"Rust":{"blanks":5,"code":12,"comments":0,"stats":[{"blanks":5,"code":12,"comments":0,"lines":17,"name":".\\src\\lib\\build.rs"}],"lines":17,"total_files":1}}"#;
/// let languages = Languages::new();
/// languages.get_statistics(&vec!["src/lib/build.rs"], &vec![".git"]);
/// let json = r#"{
/// "Rust": {
/// "blanks": 5,
/// "code": 12,
/// "comments": 0,
/// "stats": [
/// {
/// "blanks": 5,
/// "code": 12,
/// "comments": 0,
/// "lines": 17,
/// "name": ".\\src\\lib\\build.rs"
/// }
/// ],
/// "lines": 17
/// }
/// }"#;
/// let mut languages = Languages::new();
/// languages.get_statistics(&*vec!["src/lib/build.rs"], &*vec![".git"]);
///
/// assert_eq!(json, languages.to_json());
/// assert_eq!(json, languages.to_json().unwrap());
/// ```
pub fn to_json(&self) -> Result<String, serde_json::Error> {
serde_json::to_string(&self.remove_empty())
}
pub fn to_toml(&self) -> String {
toml::encode_str(&self.remove_empty())
}
/// Converts `Languages` to YAML.
///
/// ```no_run
///
/// # use tokei::*;
/// let yaml = r#"
/// ---
/// "Rust":
@ -354,12 +429,11 @@ impl Languages {
/// "code": 12
/// "comments": 0
/// "lines": 17
/// "name": ".\\src\\lib\\build.rs"
/// "total_files": 1"#;
/// let languages = Languages::new();
/// languages.get_statistics(&vec!["src/lib/build.rs"], &vec![".git"]);
/// "name": ".\\src\\lib\\build.rs"#;
/// let mut languages = Languages::new();
/// languages.get_statistics(&*vec!["src/lib/build.rs"], &*vec![".git"]);
///
/// assert_eq!(yaml, languages.to_yaml());
/// assert_eq!(yaml, languages.to_yaml().unwrap());
pub fn to_yaml(&self) -> Result<String, serde_yaml::Error> {
serde_yaml::to_string(&self.remove_empty())
}

View File

@ -4,9 +4,47 @@
unstable_features,
unused_import_braces)]
//! # Tokei: Code Analysis Library([For the binary](https://github.com/Aaronepower/tokei/))
//! # Tokei: Code Analysis Library
//!
//! Tokei is a code analysis library powering the application of the same name.
//! A simple, effcient library for analysing code in directories.[_For the binary_](https://github.com/Aaronepower/tokei/)
//!
//! ## How to use
//!
//! Tokei provides both `Languages` a map of existing programming languages and `Language` for creating custom languages.
//!
//! ### Example(Get total lines of code from all rust files in current directory, and all subdirectories)
//!
//! ```no_run
//! extern crate tokei;
//!
//! use std::collections::BTreeMap;
//! use std::fs::File;
//! use std::io::Read;
//!
//! use tokei::{Languages, LanguageType};
//!
//! fn main() {
//! // The paths to search. Accepts absolute, relative, and glob paths.
//! let paths = vec!["**/*.rs"];
//! // Exclude any path that contains any of these strings.
//! let excluded = vec!["target", ".git"];
//!
//! // Create new Languages
//! let mut languages = Languages::new();
//!
//! // Get statistics
//! languages.get_statistics(&*paths, &*excluded);
//!
//! // Remove empty languages
//! let language_map = languages.remove_empty();
//!
//! // Get Rust from statistics
//! let rust = language_map.get(&LanguageType::Rust).unwrap();
//!
//! // Print the number of lines that were code.
//! println!("Lines of code: {}", rust.code);
//! }
//! ```
#[macro_use]
extern crate maplit;

View File

@ -1,10 +1,9 @@
#[macro_use]
#![allow(missing_docs)]
mod utils;
mod language;
mod stats;
pub use language::{LanguageType, Languages, Language};
pub use stats::Stats;
pub use utils::consts;
#[macro_use]
mod utils;
mod language;
mod stats;
mod sort;
pub use language::{LanguageType, Languages, Language};
pub use stats::Stats;
pub use sort::Sort;

28
src/lib/sort.rs Normal file
View File

@ -0,0 +1,28 @@
use std::borrow::Cow;
/// Used for sorting languages.
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
pub enum Sort {
/// Sort by number blank lines.
Blanks,
/// Sort by number comments lines.
Comments,
/// Sort by number code lines.
Code,
/// Sort by number files lines.
Files,
/// Sort by number of lines.
Lines,
}
impl<'a> From<Sort> for Cow<'a, Sort> {
fn from(from: Sort) -> Self {
Cow::Owned(from)
}
}
impl<'a> From<&'a Sort> for Cow<'a, Sort> {
fn from(from: &'a Sort) -> Self {
Cow::Borrowed(from)
}
}

View File

@ -20,6 +20,7 @@ impl Stats {
/// Create a new `Stats` from a file path.
///
/// ```
/// # use tokei::*;
/// let stats = Stats::new("src/main.rs");
/// ```
pub fn new<S: Into<String>>(name: S) -> Self {

View File

@ -1,6 +0,0 @@
pub const BLANKS: &'static str = "blanks";
pub const COMMENTS: &'static str = "comments";
pub const CODE: &'static str = "code";
pub const FILES: &'static str = "files";
pub const LINES: &'static str = "lines";

View File

@ -68,7 +68,7 @@ pub fn get_all_files<'a>(paths: Cow<'a, [&'a str]>,
let mut language = if opt_or_cont!(path.to_str()).contains("Makefile") {
languages.get_mut(&Makefile).unwrap()
} else {
opt_or_cont!(
opt_or_cont!(
languages.get_mut(&opt_or_cont!(LanguageType::from_extension(&path))))
};
@ -91,8 +91,8 @@ pub fn get_all_files<'a>(paths: Cow<'a, [&'a str]>,
let mut language = if opt_or_cont!(entry.path().to_str()).contains("Makefile") {
languages.get_mut(&Makefile).unwrap()
} else {
opt_or_cont!(
languages.get_mut(&opt_or_cont!(LanguageType::from_extension(entry.path())))
opt_or_cont!(
languages.get_mut(&opt_or_cont!(LanguageType::from_extension(entry.path())))
)
};
@ -104,47 +104,47 @@ pub fn get_all_files<'a>(paths: Cow<'a, [&'a str]>,
pub fn get_extension<P: AsRef<Path>>(path: P) -> Option<String> {
let path = path.as_ref();
match path.extension() {
match path.extension() {
Some(extension_os) => {
match extension_os.to_str() {
Some(extension) => Some(extension.to_lowercase()),
None => None,
match extension_os.to_str() {
Some(extension) => Some(extension.to_lowercase()),
None => None,
}
}
}
None => {
match get_filetype_from_shebang(path) {
match get_filetype_from_shebang(path) {
// Using String::from here because all file extensions from
// get_filetype_from_shebang are guaranteed to be lowercase.
Some(extension) => Some(String::from(extension)),
None => None,
Some(extension) => Some(String::from(extension)),
None => None,
}
}
}
}
}
/// This is for getting the file type from the first line of a file
pub fn get_filetype_from_shebang<P: AsRef<Path>>(file: P) -> Option<&'static str> {
let file = match File::open(file) {
Ok(file) => file,
_ => return None,
let file = match File::open(file) {
Ok(file) => file,
_ => return None,
};
let mut buf = BufReader::new(file);
let mut line = String::new();
let _ = buf.read_line(&mut line);
let mut words = line.split_whitespace();
match words.next() {
Some("#!/bin/sh") => Some("sh"),
Some("#!/bin/csh") => Some("csh"),
Some("#!/usr/bin/perl") => Some("pl"),
match words.next() {
Some("#!/bin/sh") => Some("sh"),
Some("#!/bin/csh") => Some("csh"),
Some("#!/usr/bin/perl") => Some("pl"),
Some("#!/usr/bin/env") => {
match words.next() {
Some("python") | Some("python2") | Some("python3") => Some("py"),
Some("sh") => Some("sh"),
_ => None,
match words.next() {
Some("python") | Some("python2") | Some("python3") => Some("py"),
Some("sh") => Some("sh"),
_ => None,
}
}
_ => None,
}
_ => None,
}
}

View File

@ -2,26 +2,26 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
macro_rules! opt_or_cont {
($option:expr) => {
match $option {
Some(result) => result,
None => continue,
}
}
macro_rules! opt_or_cont {
($option:expr) => {
match $option {
Some(result) => result,
None => continue,
}
}
}
macro_rules! rs_or_cont {
($result:expr) => {
match $result {
Ok(result) => result,
Err(_) => continue,
}
}
macro_rules! rs_or_cont {
($result:expr) => {
match $result {
Ok(result) => result,
Err(_) => continue,
}
}
}
macro_rules! debug {
($fmt:expr) => (if cfg!(debug_assertions) {println!($fmt)});
($fmt:expr, $($arg:tt)*) => (if cfg!(debug_assertions) {println!($fmt, $($arg)*)});
macro_rules! debug {
($fmt:expr) => (if cfg!(debug_assertions) {println!($fmt)});
($fmt:expr, $($arg:tt)*) => (if cfg!(debug_assertions) {println!($fmt, $($arg)*)});
}

View File

@ -1,7 +1,5 @@
#[macro_use]
mod macros;
pub mod consts;
pub mod fs;
pub use self::consts::*;
pub use self::fs::*;

View File

@ -7,6 +7,7 @@ extern crate clap;
extern crate serde_cbor;
extern crate serde_json;
extern crate serde_yaml;
extern crate toml;
extern crate rustc_serialize;
extern crate tokei;
@ -23,10 +24,15 @@ use clap::App;
use rustc_serialize::hex::FromHex;
use tokei::{Languages, Language, LanguageType};
use tokei::consts::*;
use tokei::Sort::*;
pub const ROW: &'static str = "-------------------------------------------------------------------\
------------";
pub const BLANKS: &'static str = "blanks";
pub const COMMENTS: &'static str = "comments";
pub const CODE: &'static str = "code";
pub const FILES: &'static str = "files";
pub const LINES: &'static str = "lines";
fn main() {
// Get options at the beginning, so the program doesn't have to make any extra calls to get the
@ -163,11 +169,7 @@ fn main() {
}
}
"json" => print!("{}", languages.to_json().unwrap()),
// "toml" => print!("{}", {
// let encoder = toml::Encoder::new();
// lang_map.encode(&mut encoder).unwrap();
// encoder.toml
// }),
"toml" => print!("{}", languages.to_toml()),
"yaml" => print!("{}", languages.to_yaml().unwrap()),
_ => unreachable!(),
}
@ -175,11 +177,11 @@ fn main() {
for (_, ref mut language) in &mut languages {
match &*sort_category {
BLANKS => language.sort_by(BLANKS),
COMMENTS => language.sort_by(COMMENTS),
CODE => language.sort_by(CODE),
FILES => language.sort_by(FILES),
LINES => language.sort_by(LINES),
BLANKS => language.sort_by(Blanks),
COMMENTS => language.sort_by(Comments),
CODE => language.sort_by(Code),
FILES => language.sort_by(Files),
LINES => language.sort_by(Lines),
_ => unreachable!(),
}
}
@ -215,7 +217,13 @@ fn main() {
if !files_option {
println!("{}", ROW);
}
print_language(&total, LanguageType::__Total);
println!(" {: <18} {: >6} {:>12} {:>12} {:>12} {:>12}",
"Total",
total.stats.len(),
total.lines,
total.code,
total.comments,
total.blanks);
println!("{}", ROW);
}
}
@ -231,7 +239,13 @@ pub fn convert_input(contents: String) -> Option<BTreeMap<LanguageType, Language
Some(result)
} else if let Ok(result) = serde_yaml::from_str(&*contents) {
Some(result)
} else if let Ok(result) = serde_cbor::from_slice(&*contents.from_hex().unwrap()) {
} 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) {
Some(result)
} else {
None
@ -243,7 +257,7 @@ fn print_language<'a, C>(language: &'a Language, name: C)
{
println!(" {: <18} {: >6} {:>12} {:>12} {:>12} {:>12}",
name.into().name(),
language.total_files,
language.stats.len(),
language.lines,
language.code,
language.comments,