Skip to content

Commit 6eb566a

Browse files
committed
cargo-rail: cleaning out 'dead_code' or 'unused'. Fixing error messages. General cleanups.
1 parent a0b9270 commit 6eb566a

File tree

15 files changed

+65
-74
lines changed

15 files changed

+65
-74
lines changed

src/cargo/manifest_ops/fields.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub fn set_features(item: &mut Item, features: Vec<String>) -> RailResult<()> {
6363
table.insert("features", Item::Value(build_feature_array(&features)));
6464
Ok(())
6565
} else {
66-
Err(RailError::message("Cannot set features: item is not a table"))
66+
Err(RailError::message("cannot set features: item is not a table"))
6767
}
6868
}
6969

@@ -136,7 +136,7 @@ pub fn set_path(item: &mut Item, path: &str) -> RailResult<()> {
136136
table.insert("path", Item::Value(Value::from(path)));
137137
Ok(())
138138
} else {
139-
Err(RailError::message("Cannot set path: item is not a table"))
139+
Err(RailError::message("cannot set path: item is not a table"))
140140
}
141141
}
142142

@@ -170,7 +170,7 @@ pub fn set_default_features(item: &mut Item, enabled: bool) -> RailResult<()> {
170170
table.insert("default-features", Item::Value(Value::from(enabled)));
171171
Ok(())
172172
} else {
173-
Err(RailError::message("Cannot set default-features: item is not a table"))
173+
Err(RailError::message("cannot set default-features: item is not a table"))
174174
}
175175
}
176176

src/cargo/manifest_ops/navigation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn ensure_section(doc: &mut DocumentMut, path: &str) -> RailResult<()> {
3535
.ok_or_else(|| RailError::message(format!("Failed to access {}", part)))?;
3636
} else {
3737
return Err(RailError::message(
38-
"Cannot create section: expected table but found non-table",
38+
"cannot create section: expected table but found non-table",
3939
));
4040
}
4141
}
@@ -77,7 +77,7 @@ pub fn get_or_create_table<'a>(doc: &'a mut DocumentMut, path: &str) -> RailResu
7777
.ok_or_else(|| RailError::message(format!("Failed to access {}", part)))?;
7878
} else {
7979
return Err(RailError::message(format!(
80-
"Cannot navigate to {}: parent is not a table",
80+
"cannot navigate to {}: parent is not a table",
8181
part
8282
)));
8383
}

src/cargo/manifest_ops/transform.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ pub fn set_version(item: &mut Item, version: &str) -> RailResult<()> {
157157
Ok(())
158158
} else {
159159
Err(RailError::message(
160-
"Cannot set version: item is not a valid dependency format",
160+
"cannot set version: item is not a valid dependency format",
161161
))
162162
}
163163
}
@@ -186,7 +186,7 @@ pub fn set_optional(item: &mut Item, optional: bool) -> RailResult<()> {
186186
table.insert("optional", Item::Value(Value::from(optional)));
187187
Ok(())
188188
} else {
189-
Err(RailError::message("Cannot set optional: item is not a table"))
189+
Err(RailError::message("cannot set optional: item is not a table"))
190190
}
191191
}
192192

src/commands/clean.rs

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,11 @@ pub fn run_clean(ctx: &WorkspaceContext, cache: bool, backups: bool, reports: bo
2424
.join("target")
2525
.join("cargo-rail")
2626
.join("metadata.json");
27-
let old_cache = ctx.workspace_root.join("target").join("rail");
2827

2928
if cache_path.exists() {
3029
println!(" {}", cache_path.display());
3130
would_clean = true;
3231
}
33-
if old_cache.exists() {
34-
println!(" {} (legacy)", old_cache.display());
35-
would_clean = true;
36-
}
3732
}
3833

3934
if clean_reports {
@@ -111,23 +106,20 @@ pub fn run_clean(ctx: &WorkspaceContext, cache: bool, backups: bool, reports: bo
111106
}
112107

113108
fn clean_metadata_cache(ctx: &WorkspaceContext) -> RailResult<()> {
114-
let rail_target = ctx
109+
let cache_path = ctx
115110
.workspace_root
116111
.join("target")
117112
.join("cargo-rail")
118113
.join("metadata.json");
119-
let old_rail_target = ctx.workspace_root.join("target").join("rail");
120114

121-
if rail_target.exists() {
115+
if cache_path.exists() {
122116
progress!("removing cache...");
123-
fs::remove_file(&rail_target)
124-
.map_err(|e| RailError::message(format!("failed to remove {}: {}", rail_target.display(), e)))?;
125-
}
126-
127-
if old_rail_target.exists() {
128-
progress!("removing legacy cache...");
129-
fs::remove_dir_all(&old_rail_target)
130-
.map_err(|e| RailError::message(format!("failed to remove {}: {}", old_rail_target.display(), e)))?;
117+
fs::remove_file(&cache_path).map_err(|e| {
118+
RailError::with_help(
119+
format!("failed to remove {}: {}", cache_path.display(), e),
120+
"check file permissions or if the file is in use",
121+
)
122+
})?;
131123
}
132124

133125
Ok(())
@@ -138,12 +130,26 @@ fn clean_generated_reports(ctx: &WorkspaceContext) -> RailResult<()> {
138130

139131
if report_dir.exists() {
140132
progress!("removing reports...");
141-
for entry in fs::read_dir(&report_dir).map_err(|e| RailError::message(format!("failed to read dir: {}", e)))? {
142-
let entry = entry.map_err(|e| RailError::message(format!("failed to read entry: {}", e)))?;
133+
for entry in fs::read_dir(&report_dir).map_err(|e| {
134+
RailError::with_help(
135+
format!("failed to read {}: {}", report_dir.display(), e),
136+
"check directory permissions",
137+
)
138+
})? {
139+
let entry = entry.map_err(|e| {
140+
RailError::with_help(
141+
format!("failed to read directory entry: {}", e),
142+
"check directory permissions",
143+
)
144+
})?;
143145
let path = entry.path();
144146
if path.is_file() && path.extension().is_some_and(|ext| ext == "md") {
145-
fs::remove_file(&path)
146-
.map_err(|e| RailError::message(format!("failed to remove {}: {}", path.display(), e)))?;
147+
fs::remove_file(&path).map_err(|e| {
148+
RailError::with_help(
149+
format!("failed to remove {}: {}", path.display(), e),
150+
"check file permissions or if the file is in use",
151+
)
152+
})?;
147153
}
148154
}
149155
}

src/commands/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ impl<'a> SplitSyncConfigBuilder<'a> {
136136
self.with_crate(&name)
137137
} else {
138138
Err(RailError::with_help(
139-
"Must specify a crate name or use --all",
139+
"must specify a crate name or use --all",
140140
"Try: cargo rail <command> --all OR cargo rail <command> <crate-name>",
141141
))
142142
}

src/commands/unify.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,14 @@ pub fn run_unify_analyze(
9494
if !dep.features.is_empty() {
9595
let mut features = dep.features.clone();
9696
features.sort();
97-
println!(" features = {:?}", features);
97+
println!(
98+
" features = [{}]",
99+
features
100+
.iter()
101+
.map(|f| format!("\"{}\"", f))
102+
.collect::<Vec<_>>()
103+
.join(", ")
104+
);
98105
}
99106
}
100107
println!();
@@ -135,7 +142,14 @@ pub fn run_unify_analyze(
135142
if !local_features.is_empty() {
136143
let mut features = local_features.clone();
137144
features.sort();
138-
line.push_str(&format!(", features = {:?}", features));
145+
line.push_str(&format!(
146+
", features = [{}]",
147+
features
148+
.iter()
149+
.map(|f| format!("\"{}\"", f))
150+
.collect::<Vec<_>>()
151+
.join(", ")
152+
));
139153
}
140154
if *is_optional {
141155
line.push_str(", optional = true");

src/config/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,7 @@ impl RailConfig {
201201
.collect()
202202
}
203203

204-
/// Helper to build all SplitConfigs from unified crate config
205-
/// Used for backward compatibility with commands expecting `Vec<SplitConfig>`
204+
/// Build all SplitConfigs from unified crate config
206205
pub fn build_split_configs(&self) -> Vec<SplitConfig> {
207206
self
208207
.crates

src/config/release.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ pub struct ChangelogConfig {
139139
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
140140
#[serde(rename_all = "lowercase")]
141141
pub enum ChangelogRelativeTo {
142-
/// Relative to each crate's directory (default, backward compatible)
142+
/// Relative to each crate's directory (default)
143143
/// With this, `changelog_path = "CHANGELOG.md"` creates `crates/foo/CHANGELOG.md`
144144
#[default]
145145
Crate,
@@ -210,7 +210,7 @@ mod tests {
210210

211211
#[test]
212212
fn test_changelog_relative_to_defaults_to_crate() {
213-
// When not specified, should default to "crate" for backward compatibility
213+
// When not specified, should default to "crate"
214214
let toml = r#"
215215
changelog_path = "CHANGELOG.md"
216216
"#;

src/config/unify.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub struct UnifyConfig {
1212

1313
/// Handle renamed dependencies (package = "...")? (default: false)
1414
/// Renamed deps are tricky to unify correctly, opt-in only
15-
#[serde(default, alias = "allow_renamed")]
15+
#[serde(default)]
1616
pub include_renamed: bool,
1717

1818
/// Pin transitive-only deps with fragmented features? (default: true)
@@ -170,7 +170,7 @@ impl<'de> Deserialize<'de> for TransitiveFeatureHost {
170170
E: serde::de::Error,
171171
{
172172
match value {
173-
"root" | "auto" => Ok(TransitiveFeatureHost::Root), // "auto" for backward compatibility
173+
"root" => Ok(TransitiveFeatureHost::Root),
174174
path => Ok(TransitiveFeatureHost::Path(path.to_string())),
175175
}
176176
}

src/git/ops.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ impl SystemGit {
2323
///
2424
/// Returns commits in reverse chronological order (newest first).
2525
/// Uses parallel batch processing for optimal performance.
26-
/// The _path parameter is kept for API compatibility but currently unused.
27-
pub fn commit_history(&self, _path: &Path, limit: Option<usize>) -> RailResult<Vec<CommitInfo>> {
26+
pub fn commit_history(&self, limit: Option<usize>) -> RailResult<Vec<CommitInfo>> {
2827
let mut args = vec!["log", "--format=%H"];
2928
let limit_str;
3029
if let Some(max) = limit {
@@ -619,7 +618,7 @@ mod tests {
619618
let git = SystemGit::open(&find_git_root()).unwrap();
620619

621620
// Test with limit
622-
let commits = git.commit_history(Path::new("."), Some(5)).unwrap();
621+
let commits = git.commit_history(Some(5)).unwrap();
623622
assert!(!commits.is_empty());
624623
assert!(commits.len() <= 5);
625624

@@ -653,7 +652,7 @@ mod tests {
653652
let git = SystemGit::open(&find_git_root()).unwrap();
654653

655654
// Get some commit SHAs
656-
let history = git.commit_history(Path::new("."), Some(5)).unwrap();
655+
let history = git.commit_history(Some(5)).unwrap();
657656
let shas: Vec<String> = history.iter().map(|c| c.sha.clone()).collect();
658657

659658
// Fetch them in bulk

0 commit comments

Comments
 (0)