Skip to content

Commit

Permalink
Switch from json to serde_json; bump version to 0.6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
peap committed Jun 8, 2024
1 parent 339352c commit a69552b
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 38 deletions.
54 changes: 46 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

name = "git-global"
version = "0.6.1"
version = "0.6.2"
authors = ["Eric Petersen <[email protected]>"]
description = "Keep track of all the git repositories on your machine."

Expand Down Expand Up @@ -35,7 +35,7 @@ manpage = ["man"]

[dependencies]
directories = "5"
json = "0.12" # Unmaintained (RUSTSEC-2022-0081)
serde_json = "1"
walkdir = "2"

[dev-dependencies]
Expand All @@ -53,3 +53,7 @@ default-features = false # don't need SSH/HTTPS
[dependencies.man]
version = "0.3"
optional = true

[dependencies.serde]
version = "1"
features = ["derive"]
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ The following are some ideas about future subcommands and features:

## Release Notes

* 0.6.2 (2024-06-08)
* Various dependency updates, including `json` --> `serde_json`.
* 0.6.1 (2023-08-10)
* Various dependency updates.
* 0.6.0 (2023-05-10)
Expand Down
12 changes: 6 additions & 6 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::io::{stderr, stdout, Write};

use clap::{command, Arg, ArgAction, ArgMatches, Command};
use json::object;
use serde_json::json;

use crate::config::Config;
use crate::subcommands;
Expand Down Expand Up @@ -76,11 +76,11 @@ pub fn run_from_command_line() -> i32 {
}
Err(err) => {
if use_json {
let json = object! {
"error" => true,
"message" => format!("{}", err)
};
writeln!(&mut stderr(), "{:#}", json).unwrap();
let out = json!({
"error": true,
"message": format!("{}", err)
});
writeln!(&mut stderr(), "{:#}", out).unwrap();
} else {
writeln!(&mut stderr(), "{}", err).unwrap();
}
Expand Down
4 changes: 3 additions & 1 deletion src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
use std::fmt;
use std::path::PathBuf;

use serde::Serialize;

/// A git repository, represented by the full path to its base directory.
#[derive(Clone, Eq, Hash, PartialEq)]
#[derive(Clone, Eq, Hash, PartialEq, Serialize)]
pub struct Repo {
path: PathBuf,
}
Expand Down
30 changes: 9 additions & 21 deletions src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::collections::HashMap;
use std::io::Write;

use json::{array, object};
use serde_json::json;

use crate::repo::Repo;

Expand Down Expand Up @@ -73,28 +73,16 @@ impl Report {

/// Writes all result messages to the given writer, as JSON.
pub fn print_json<W: Write>(&self, writer: &mut W) {
let mut json = object! {
"error" => false,
"messages" => array![],
"repo_messages" => object!{}
};
for msg in self.messages.iter() {
json["results"]["messages"]
.push(msg.to_string())
.expect("Failing pushing message to JSON messages array.");
}
let mut repo_messages: HashMap<String, Vec<&String>> = HashMap::new();
for (repo, messages) in self.repo_messages.iter() {
json["repo_messages"][repo.path()] = array![];
if !messages.is_empty() {
for line in messages.iter().filter(|l| !l.is_empty()) {
json["repo_messages"][repo.path()]
.push(line.to_string())
.expect(
"Failed pushing line to JSON repo-messages array.",
);
}
}
let msgs = messages.iter().filter(|l| !l.is_empty());
repo_messages.insert(repo.path(), msgs.collect());
}
let json = json!({
"error": false,
"messages": self.messages,
"repo_messages": repo_messages
});
writeln!(writer, "{:#}", json).unwrap();
}
}

0 comments on commit a69552b

Please sign in to comment.