1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
use std::collections::HashMap;
use anyhow::Result;
use clap::Parser;
use colored::*;
mod cli;
fn main() -> Result<()> {
let args = cli::Cli::parse();
match args.command {
cli::Commands::Bless(opts) => {
println!("🔥 cargo-bless v{}", env!("CARGO_PKG_VERSION"));
println!();
// Handle --update-rules before the main pipeline
if opts.update_rules {
cargo_bless::updater::update_rules()?;
println!();
println!("Rules updated. Run `cargo bless` to use them.");
return Ok(());
}
if opts.llm {
println!(
"{}",
"LLM-powered suggestions are not yet implemented. Stay tuned!".yellow()
);
println!();
}
if opts.fix {
if opts.dry_run {
println!("🔍 Dry-run mode — previewing changes (no files will be modified)");
} else {
println!("🔧 Fix mode — applying safe changes");
}
println!();
}
println!("📋 Scanning dependencies...");
println!();
// Parse the dep tree
let manifest = opts.manifest_path.as_deref();
let deps = cargo_bless::parser::get_deps(manifest)?;
let (project_name, project_version) = cargo_bless::parser::get_project_info(manifest)?;
let direct: Vec<_> = deps.iter().filter(|d| d.is_direct).collect();
let transitive: Vec<_> = deps.iter().filter(|d| !d.is_direct).collect();
// Print direct dependencies
println!(
"{}",
format!("📦 Direct dependencies ({})", direct.len()).bold()
);
for dep in &direct {
let features_str = if dep.features.is_empty() {
String::new()
} else {
format!(" [{}]", dep.features.join(", "))
};
println!(
" {} {} {}{}",
"•".green(),
dep.name.bold(),
dep.version.dimmed(),
features_str.dimmed()
);
}
println!();
println!(
"{}",
format!("📎 Transitive dependencies ({})", transitive.len()).dimmed()
);
println!();
println!(
"{}",
format!("Found {} direct deps, {} total.", direct.len(), deps.len()).bold()
);
// Suggestion engine: load rules → analyze
println!();
let rules = cargo_bless::suggestions::load_rules();
let suggestions = cargo_bless::suggestions::analyze(&deps, &rules);
// Live intelligence: fetch metadata for flagged deps (non-fatal)
let intel = if !suggestions.is_empty() {
// Collect unique crate names from suggestions
let crate_names: Vec<&str> = suggestions
.iter()
.flat_map(|s| s.current.split('+'))
.collect();
match cargo_bless::intel::IntelClient::new() {
Ok(client) => {
println!("{}", "🌐 Fetching live intelligence...".dimmed());
let result = client.fetch_bulk_intel(&crate_names);
if result.is_empty() && !crate_names.is_empty() {
println!(
"{}",
"⚠️ Live data unavailable (offline or rate-limited)"
.yellow()
.dimmed()
);
}
println!();
result
}
Err(_) => {
println!(
"{}",
"⚠️ Could not initialize live intelligence (continuing without)"
.yellow()
.dimmed()
);
println!();
HashMap::new()
}
}
} else {
HashMap::new()
};
// Render the report
cargo_bless::output::render_report(
&project_name,
&project_version,
&suggestions,
&intel,
);
// Apply fixes if --fix was passed
if opts.fix && !suggestions.is_empty() {
println!();
let manifest = opts
.manifest_path
.clone()
.unwrap_or_else(|| std::path::PathBuf::from("Cargo.toml"));
cargo_bless::fix::apply(&suggestions, &manifest, opts.dry_run)?;
}
Ok(())
}
}
}