Skip to content

Commit 04d179a

Browse files
authored
feat: gate cli features (#41)
* feat: gate cli features * chore: clippy::unnecessary_unwrap * chore: make `cli` a default feature * chore: clippy::unnecessary_pass_by_value * chore: clippy_manual_let_else * chore: clippy::single_char_pattern * chore: clippy::explicit_iter_loop * typo: delimeter -> delimiter * typo: cloumn -> column * chore: cargo +nightly fmt
1 parent 95a4f50 commit 04d179a

File tree

9 files changed

+46
-27
lines changed

9 files changed

+46
-27
lines changed

Cargo.toml

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,44 @@ path = "examples/main.rs"
2222
[[bin]]
2323
name = "toon"
2424
path = "src/cli/main.rs"
25+
required-features = ["cli"]
26+
27+
[features]
28+
default = ["cli"]
29+
cli = [
30+
"dep:clap",
31+
"dep:anyhow",
32+
"dep:tiktoken-rs",
33+
"dep:comfy-table",
34+
"dep:ratatui",
35+
"dep:crossterm",
36+
"dep:tui-textarea",
37+
"dep:arboard",
38+
"dep:syntect",
39+
"dep:unicode-width",
40+
"dep:chrono",
41+
]
2542

2643
[dependencies]
2744
serde = { version = "1.0.228", features = ["derive"] }
2845
indexmap = "2.0"
2946
serde_json = { version = "1.0.145", features = ["preserve_order"] }
3047
thiserror = "2.0.17"
3148

32-
clap = { version = "4.5.11", features = ["derive"] }
33-
anyhow = "1.0.86"
34-
tiktoken-rs = "0.9.1"
35-
comfy-table = "7.1"
36-
37-
# TUI dependencies
38-
ratatui = "0.29"
39-
crossterm = "0.28"
40-
tui-textarea = "0.7"
41-
arboard = "3.4"
42-
syntect = "5.2"
43-
unicode-width = "0.2"
44-
chrono = "0.4"
49+
# CLI dependencies (gated behind "cli" feature)
50+
clap = { version = "4.5.11", features = ["derive"], optional = true }
51+
anyhow = { version = "1.0.86", optional = true }
52+
tiktoken-rs = { version = "0.9.1", optional = true }
53+
comfy-table = { version = "7.1", optional = true }
54+
55+
# TUI dependencies (gated behind "cli" feature)
56+
ratatui = { version = "0.29", optional = true }
57+
crossterm = { version = "0.28", optional = true }
58+
tui-textarea = { version = "0.7", optional = true }
59+
arboard = { version = "3.4", optional = true }
60+
syntect = { version = "5.2", optional = true }
61+
unicode-width = { version = "0.2", optional = true }
62+
chrono = { version = "0.4", optional = true }
4563

4664
[dev-dependencies]
4765
datatest-stable = "0.3.3"

src/decode/parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ impl<'a> Parser<'a> {
651651

652652
if let Some(fields) = fields {
653653
validation::validate_field_list(&fields)?;
654-
self.parse_tabular_array(length, fields, depth, context)
654+
self.parse_tabular_array(length, &fields, depth, context)
655655
} else {
656656
// Non-tabular arrays as first field of list items require depth adjustment
657657
// (items at depth +2 relative to hyphen, not the usual +1)
@@ -666,7 +666,7 @@ impl<'a> Parser<'a> {
666666
fn parse_tabular_array(
667667
&mut self,
668668
length: usize,
669-
fields: Vec<String>,
669+
fields: &[String],
670670
depth: usize,
671671
context: ArrayParseContext,
672672
) -> ToonResult<Value> {

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
pub mod constants;
2929
pub mod decode;
3030
pub mod encode;
31+
#[cfg(feature = "cli")]
3132
pub mod tui;
3233
pub mod types;
3334
pub mod utils;

src/types/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
mod delimeter;
1+
mod delimiter;
22
mod errors;
33
mod folding;
44
mod options;
55
mod value;
66

7-
pub use delimeter::Delimiter;
7+
pub use delimiter::Delimiter;
88
pub use errors::{
99
ErrorContext,
1010
ToonError,

src/utils/string.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,10 @@ pub fn is_valid_unquoted_key(key: &str) -> bool {
100100
}
101101

102102
let mut chars = key.chars();
103-
let first = match chars.next() {
104-
Some(c) => c,
105-
None => return false,
103+
let first = if let Some(c) = chars.next() {
104+
c
105+
} else {
106+
return false;
106107
};
107108

108109
if !first.is_alphabetic() && first != '_' {
@@ -142,7 +143,7 @@ pub fn needs_quoting(s: &str, delimiter: char) -> bool {
142143
return true;
143144
}
144145

145-
if s.starts_with("-") {
146+
if s.starts_with('-') {
146147
return true;
147148
}
148149

src/utils/validation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ pub fn validate_field_name(name: &str) -> ToonResult<()> {
2929
pub fn validate_value(value: &Value) -> ToonResult<()> {
3030
match value {
3131
Value::Object(obj) => {
32-
for (key, val) in obj.iter() {
32+
for (key, val) in obj {
3333
validate_field_name(key)?;
3434
validate_value(val)?;
3535
}
3636
}
3737
Value::Array(arr) => {
38-
for val in arr.iter() {
38+
for val in arr {
3939
validate_value(val)?;
4040
}
4141
}

tests/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ fn test_tabular_array_errors() {
143143
let err_str = e.to_string();
144144
assert!(
145145
err_str.contains("Parse")
146-
|| err_str.contains("cloumn")
146+
|| err_str.contains("column")
147147
|| err_str.contains("expected")
148148
|| err_str.contains("primitive"),
149149
"Error should mention missing field or delimiter: {err_str}"

tests/spec_fixtures.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,10 @@ fn test_decode_fixtures(path: &Utf8Path, contents: String) -> datatest_stable::R
7777
let result = decode::<Value>(toon_input, &opts);
7878

7979
if test.should_error {
80-
if result.is_ok() {
80+
if let Ok(actual_json) = result {
8181
return Err(format!(
8282
"Test '{}' should have FAILED, but it succeeded with: {:?}",
83-
test_name,
84-
result.unwrap()
83+
test_name, actual_json
8584
)
8685
.into());
8786
}

0 commit comments

Comments
 (0)