mirror of
https://github.com/o2sh/onefetch
synced 2024-07-05 00:58:35 +00:00
Commit of missing changes of last commit
This commit is contained in:
parent
65c7a54510
commit
9993dcb0ec
24
Cargo.lock
generated
24
Cargo.lock
generated
|
@ -953,6 +953,9 @@ dependencies = [
|
|||
"more-asserts",
|
||||
"paste",
|
||||
"regex",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_test",
|
||||
"strum",
|
||||
"term_size",
|
||||
"tokei",
|
||||
|
@ -1276,18 +1279,18 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
|
|||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.117"
|
||||
version = "1.0.118"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b88fa983de7720629c9387e9f517353ed404164b1e482c970a90c1a4aaf7dc1a"
|
||||
checksum = "06c64263859d87aa2eb554587e2d23183398d617427327cf2b3d0ed8c69e4800"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.117"
|
||||
version = "1.0.118"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cbd1ae72adb44aab48f325a02444a5fc079349a8d804c1fc922aed3f7454c74e"
|
||||
checksum = "c84d3526699cd55261af4b941e4e725444df67aa4f9e6a3564f18030d12672df"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -1296,15 +1299,24 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.58"
|
||||
version = "1.0.60"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a230ea9107ca2220eea9d46de97eddcb04cd00e92d13dda78e478dd33fa82bd4"
|
||||
checksum = "1500e84d27fe482ed1dc791a56eddc2f230046a040fa908c08bda1d9fb615779"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_test"
|
||||
version = "1.0.118"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f7f3f8714511d29f60be0ea965bc784df1b6903da5bbac801df36b1bbc7b4880"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha-1"
|
||||
version = "0.8.2"
|
||||
|
|
|
@ -33,6 +33,8 @@ image = "0.23.12"
|
|||
regex = "1"
|
||||
error-chain = "0.12"
|
||||
toml = "0.5.7"
|
||||
serde = "1.0.118"
|
||||
serde_json = "1.0.60"
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
ansi_term = "0.12"
|
||||
|
@ -44,6 +46,7 @@ base64 = "0.13.0"
|
|||
[dev-dependencies]
|
||||
more-asserts = "0.2"
|
||||
paste = "1"
|
||||
serde_test = "1.0.117"
|
||||
|
||||
[features]
|
||||
fail-on-deprecated = []
|
||||
|
|
|
@ -30,11 +30,17 @@ fn run() -> Result<()> {
|
|||
return Err("please run onefetch inside of a non-bare git repository".into());
|
||||
}
|
||||
|
||||
let print_json = config.print_json;
|
||||
|
||||
let info = info::Info::new(config)?;
|
||||
|
||||
let mut printer = Printer::new(io::BufWriter::new(io::stdout()), info);
|
||||
|
||||
printer.print()?;
|
||||
if print_json {
|
||||
printer.print_json()?;
|
||||
} else {
|
||||
printer.print()?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ pub struct Cli {
|
|||
pub excluded: Vec<String>,
|
||||
pub print_languages: bool,
|
||||
pub print_package_managers: bool,
|
||||
pub print_json: bool,
|
||||
pub true_color: bool,
|
||||
pub art_off: bool,
|
||||
pub text_colors: Vec<String>,
|
||||
|
@ -228,6 +229,12 @@ impl Cli {
|
|||
.takes_value(true)
|
||||
.help("Ignore all files & directories matching EXCLUDE."),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("json")
|
||||
.short("j")
|
||||
.long("json")
|
||||
.help("Print out a json representation of the normal onefetch output")
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
let true_color = cli_utils::is_truecolor_terminal();
|
||||
|
@ -236,6 +243,7 @@ impl Cli {
|
|||
let no_color_palette = matches.is_present("no-color-palette");
|
||||
let print_languages = matches.is_present("languages");
|
||||
let print_package_managers = matches.is_present("package-managers");
|
||||
let print_json = matches.is_present("json");
|
||||
|
||||
let fields_to_hide: Vec<String> = if let Some(values) = matches.values_of("disable-fields")
|
||||
{
|
||||
|
@ -331,6 +339,7 @@ impl Cli {
|
|||
excluded,
|
||||
print_languages,
|
||||
print_package_managers,
|
||||
print_json,
|
||||
true_color,
|
||||
text_colors,
|
||||
art_off,
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
use git2::Oid;
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct CommitInfo {
|
||||
#[serde(skip_serializing)]
|
||||
commit: Oid,
|
||||
refs: Vec<String>,
|
||||
}
|
||||
|
|
|
@ -4,8 +4,11 @@ use {
|
|||
language::Language, license::Detector, repo::Repo, text_color::TextColor,
|
||||
},
|
||||
colored::{Color, ColoredString, Colorize},
|
||||
// serde::ser::{Serialize, SerializeStruct, Serializer},
|
||||
serde::Serialize,
|
||||
};
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct Info {
|
||||
git_username: String,
|
||||
git_version: String,
|
||||
|
@ -26,8 +29,11 @@ pub struct Info {
|
|||
repo_size: String,
|
||||
license: String,
|
||||
pub dominant_language: Language,
|
||||
// #[serde(with = "Vec<ColorDef>")]
|
||||
#[serde(skip_serializing)]
|
||||
pub ascii_colors: Vec<Color>,
|
||||
pub text_colors: TextColor,
|
||||
#[serde(skip_serializing)]
|
||||
pub config: Cli,
|
||||
}
|
||||
|
||||
|
@ -371,3 +377,14 @@ impl Info {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// impl Serialize for Info {
|
||||
// fn serialize<S>(&self, serializer: S) -> Result<S::Ok>
|
||||
// where
|
||||
// S: Serializer,
|
||||
// {
|
||||
// let mut state = serializer.serialize_struct("Info", 19)?;
|
||||
|
||||
// state.end()
|
||||
// }
|
||||
// }
|
||||
|
|
|
@ -2,6 +2,7 @@ use {
|
|||
crate::onefetch::{error::*, utils::num_to_color},
|
||||
colored::Color,
|
||||
regex::Regex,
|
||||
serde::Serialize,
|
||||
std::collections::HashMap,
|
||||
std::env,
|
||||
strum::{EnumIter, EnumString, IntoStaticStr},
|
||||
|
@ -22,7 +23,7 @@ macro_rules! define_languages {
|
|||
($( { $name:ident, $ascii:literal, $display:literal, $colors:expr $(, $serialize:literal )? } ),* ,) => {
|
||||
|
||||
#[strum(serialize_all = "lowercase")]
|
||||
#[derive(PartialEq, Eq, Hash, Clone, EnumString, EnumIter, IntoStaticStr)]
|
||||
#[derive(PartialEq, Eq, Hash, Clone, EnumString, EnumIter, IntoStaticStr, Serialize)]
|
||||
pub enum Language {
|
||||
$(
|
||||
$( #[strum(serialize = $serialize)] )?
|
||||
|
|
|
@ -12,5 +12,6 @@ mod language;
|
|||
mod license;
|
||||
pub mod printer;
|
||||
pub mod repo;
|
||||
mod serializer;
|
||||
mod text_color;
|
||||
mod utils;
|
||||
|
|
|
@ -71,6 +71,11 @@ impl<W: Write> Printer<W> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn print_json(&mut self) -> Result<()> {
|
||||
write!(self.writer, "{}", serde_json::to_string_pretty(&self.info).unwrap())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_ascii(&self) -> &str {
|
||||
let language = if let Some(ascii_language) = &self.info.config.ascii_language {
|
||||
ascii_language
|
||||
|
|
|
@ -1,11 +1,21 @@
|
|||
use {crate::onefetch::utils::num_to_color, colored::Color};
|
||||
use {
|
||||
crate::onefetch::serializer::ColorDef, crate::onefetch::utils::num_to_color, colored::Color,
|
||||
serde::Serialize,
|
||||
};
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct TextColor {
|
||||
#[serde(with = "ColorDef")]
|
||||
pub title: Color,
|
||||
#[serde(with = "ColorDef")]
|
||||
pub tilde: Color,
|
||||
#[serde(with = "ColorDef")]
|
||||
pub underline: Color,
|
||||
#[serde(with = "ColorDef")]
|
||||
pub subtitle: Color,
|
||||
#[serde(with = "ColorDef")]
|
||||
pub colon: Color,
|
||||
#[serde(with = "ColorDef")]
|
||||
pub info: Color,
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user