Skip to content

Commit 8e4745f

Browse files
committed
Properly feature gate features
1 parent f2ece8a commit 8e4745f

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

bin/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ categories = ["command-line-utilities"]
1515
[dependencies]
1616
structopt = "0.3.14"
1717
console = "0.11.2"
18-
git-anger-library = { path = "../lib", version = "0.7.0" }
18+
git-anger-library = { path = "../lib", version = "0.7.0", features=["table", "json"] }

lib/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ serde = { version = "1.0", features = ["derive"], optional = true }
2020
serde_json = { version = "1.0", optional = true }
2121

2222
[features]
23-
default = ["json", "table"]
23+
default = []
2424
json = ["serde", "serde_json"]
2525
table = ["tabwriter"]

lib/src/author.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
#[cfg(feature = "json")]
12
use serde::Serialize;
23
use std::collections::HashMap;
34

45
/// An author of a git commit.
5-
#[derive(Debug, Serialize)]
6+
#[derive(Debug)]
7+
#[cfg_attr(feature = "json", derive(Serialize))]
68
pub struct Author {
79
/// Name of the author.
810
pub name: String,

lib/src/repo.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ use crate::{
33
core::{naughty_word, split_into_clean_words},
44
};
55
use git2::{Commit, Repository};
6+
#[cfg(feature = "json")]
67
use serde::Serialize;
78
use std::{collections::HashMap, env, error::Error, io, io::Write, path::Path};
9+
#[cfg(feature = "table")]
810
use tabwriter::TabWriter;
911

1012
/// A simple representation of a git repository.
11-
#[derive(Debug, Serialize)]
13+
#[derive(Debug)]
14+
#[cfg_attr(feature = "json", derive(Serialize))]
1215
pub struct Repo {
1316
/// Name of the repository.
1417
pub name: String,
@@ -77,6 +80,7 @@ impl Repo {
7780
}
7881

7982
/// Serialize the `Repo` struct into a JSON-object and print it.
83+
#[cfg(feature = "json")]
8084
pub fn print_json(&self) -> Result<(), Box<dyn Error>> {
8185
let serialized = serde_json::to_string(&self)?;
8286
write!(io::stdout(), "{}", serialized)?;
@@ -86,6 +90,7 @@ impl Repo {
8690
}
8791

8892
/// Build a table to display naughty authors and their words.
93+
#[cfg(feature = "table")]
8994
pub fn print_list(&self) -> Result<(), Box<dyn Error>> {
9095
let mut tw = TabWriter::new(vec![]);
9196
let curses = Repo::sort(&self.curses);
@@ -108,6 +113,7 @@ impl Repo {
108113
}
109114

110115
/// Create a sorted `Vec` from a HashMap of curses, sorted by counts
116+
#[cfg(feature = "table")]
111117
fn sort(curses: &HashMap<String, usize>) -> Vec<(String, usize)> {
112118
let mut curses: Vec<(&String, &usize)> = curses.iter().collect();
113119
curses.sort_by(|(a, _), (b, _)| a.cmp(b));
@@ -119,6 +125,7 @@ impl Repo {
119125
}
120126

121127
/// Add headers to a table
128+
#[cfg(feature = "table")]
122129
fn table_headers(
123130
&self,
124131
tw: &mut TabWriter<Vec<u8>>,
@@ -140,6 +147,7 @@ impl Repo {
140147
}
141148

142149
/// Add separators (`----`) to a table based on word lengths.
150+
#[cfg(feature = "table")]
143151
fn table_separators(
144152
&self,
145153
tw: &mut TabWriter<Vec<u8>>,
@@ -160,6 +168,7 @@ impl Repo {
160168
}
161169

162170
/// Add all the naughty authors to the table.
171+
#[cfg(feature = "table")]
163172
fn table_authors(
164173
&self,
165174
tw: &mut TabWriter<Vec<u8>>,
@@ -191,6 +200,7 @@ impl Repo {
191200
}
192201

193202
/// Sum up the total naughty count and print it.
203+
#[cfg(feature = "table")]
194204
fn table_total(
195205
&self,
196206
tw: &mut TabWriter<Vec<u8>>,

0 commit comments

Comments
 (0)