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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
//! Lock command handler - manage version lock files
use std::path::Path;
use crate::cli::LockAction;
use crate::config;
use crate::lock;
/// Handle lock subcommands
pub fn run_lock(action: &LockAction) -> i32 {
match action {
LockAction::Generate { file, output } => {
let config = config::Config::new(file);
let tools = config.get_tool_configs();
println!("Generating lock file from {}...", file);
match lock::generate_lock(&tools) {
Ok(lock_file) => {
let path = Path::new(output);
match lock_file.save(path) {
Ok(()) => {
println!("Lock file generated: {}", output);
println!(" Tools locked: {}", lock_file.tools.len());
}
Err(e) => {
eprintln!("Failed to save lock file: {}", e);
return 1;
}
}
}
Err(e) => {
eprintln!("Failed to generate lock file: {}", e);
return 1;
}
}
}
LockAction::Status { lock_file, verbose } => {
let path = Path::new(lock_file);
if !path.exists() {
eprintln!("Lock file not found: {}", lock_file);
eprintln!("Generate one with: jarvy lock generate");
return 1;
}
match lock::LockFile::load(path) {
Ok(lock) => {
let platform = std::env::consts::OS;
let result = lock::verify_lock(&lock, platform);
println!("Lock File Status");
println!("================");
println!("File: {}", lock_file);
println!("Version: {}", lock.version);
println!("Tools: {}", lock.tools.len());
println!();
if *verbose {
for tool in &result.tools {
let status_icon = match tool.status {
lock::VerificationStatus::Match => "✓",
lock::VerificationStatus::VersionMismatch => "✗",
lock::VerificationStatus::NotInstalled => "○",
lock::VerificationStatus::NotLocked => "?",
lock::VerificationStatus::Unknown => "?",
};
let installed = tool.installed_version.as_deref().unwrap_or("-");
println!(
" {} {} (locked: {}, installed: {})",
status_icon, tool.name, tool.locked_version, installed
);
}
println!();
}
println!(
"Summary: {} matched, {} mismatched, {} missing",
result.matched, result.mismatched, result.missing
);
if result.all_match {
println!("Status: All tools match lock file ✓");
} else {
println!("Status: Some tools differ from lock file");
}
}
Err(e) => {
eprintln!("Failed to load lock file: {}", e);
return 1;
}
}
}
LockAction::Verify {
lock_file,
output_format,
} => {
let path = Path::new(lock_file);
if !path.exists() {
eprintln!("Lock file not found: {}", lock_file);
return 1;
}
match lock::LockFile::load(path) {
Ok(lock) => {
let platform = std::env::consts::OS;
let result = lock::verify_lock(&lock, platform);
if output_format == "json" {
// JSON output
let output: Vec<serde_json::Value> = result
.tools
.iter()
.map(|t| {
serde_json::json!({
"name": t.name,
"status": t.status.to_string(),
"locked_version": t.locked_version,
"installed_version": t.installed_version,
})
})
.collect();
println!(
"{}",
serde_json::to_string_pretty(&output).unwrap_or_default()
);
} else {
// Pretty output
for tool in &result.tools {
let color = match tool.status {
lock::VerificationStatus::Match => "\x1b[32m",
lock::VerificationStatus::VersionMismatch => "\x1b[33m",
lock::VerificationStatus::NotInstalled => "\x1b[31m",
_ => "\x1b[90m",
};
let reset = "\x1b[0m";
let installed = tool.installed_version.as_deref().unwrap_or("-");
println!(
"{}{}{}: locked={}, installed={} [{}]",
color,
tool.name,
reset,
tool.locked_version,
installed,
tool.status
);
}
}
if !result.all_match {
return 1;
}
}
Err(e) => {
eprintln!("Failed to load lock file: {}", e);
return 1;
}
}
}
}
0
}