Skip to content

Commit

Permalink
Merge pull request #242 from deg4uss3r/241_fix_json_output
Browse files Browse the repository at this point in the history
Fix #241 JSON output formatting
  • Loading branch information
Ricky authored Oct 29, 2020
2 parents 3416541 + 9d35422 commit d090739
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cargo-outdated"
version = "0.9.12"
version = "0.9.13"
authors = [
"Kevin K. <[email protected]>",
"Frederick Z. <[email protected]>",
Expand Down
24 changes: 19 additions & 5 deletions src/cargo_ops/elaborate_workspace.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::cell::RefCell;
use std::collections::{BTreeSet, HashMap, HashSet, VecDeque};
use std::cmp::Ordering;
use std::collections::{BTreeSet, HashMap, VecDeque};
use std::io::{self, Write};

use anyhow::anyhow;
Expand Down Expand Up @@ -31,10 +32,10 @@ pub struct ElaborateWorkspace<'ela> {
#[derive(Serialize, Deserialize)]
pub struct CrateMetadata {
pub crate_name: String,
pub dependencies: HashSet<Metadata>,
pub dependencies: BTreeSet<Metadata>,
}

#[derive(Serialize, Deserialize, Eq, Hash, PartialEq)]
#[derive(Serialize, Deserialize, Eq, PartialEq)]
pub struct Metadata {
pub name: String,
pub project: String,
Expand All @@ -44,6 +45,19 @@ pub struct Metadata {
pub platform: Option<String>,
}


impl Ord for Metadata {
fn cmp(&self, other: &Self) -> Ordering {
self.name.cmp(&other.name)
}
}

impl PartialOrd for Metadata {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}

impl<'ela> ElaborateWorkspace<'ela> {
/// Elaborate a `Workspace`
pub fn from_workspace(
Expand Down Expand Up @@ -343,7 +357,7 @@ impl<'ela> ElaborateWorkspace<'ela> {
pub fn print_json(&'ela self, options: &Options, root: PackageId) -> CargoResult<i32> {
let mut crate_graph = CrateMetadata {
crate_name: root.name().to_string(),
dependencies: HashSet::new(),
dependencies: BTreeSet::new(),
};
let mut queue = VecDeque::new();
queue.push_back(vec![root]);
Expand Down Expand Up @@ -425,7 +439,7 @@ impl<'ela> ElaborateWorkspace<'ela> {
}
}

serde_json::to_writer(io::stdout(), &crate_graph)?;
println!("{}", serde_json::to_string(&crate_graph)?);

Ok(crate_graph.dependencies.len() as i32)
}
Expand Down

0 comments on commit d090739

Please sign in to comment.