Skip to content

Commit ffdc89b

Browse files
committed
print results as json in non-core commands
1 parent 2f23a8a commit ffdc89b

File tree

1 file changed

+123
-1
lines changed

1 file changed

+123
-1
lines changed

tmc-langs-cli/src/main.rs

Lines changed: 123 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,16 @@ fn run() -> Result<()> {
7676
let locale = matches.value_of("locale").unwrap();
7777
let locale = into_locale(locale)?;
7878

79-
run_checkstyle(exercise_path, output_path, locale)?
79+
run_checkstyle(exercise_path, output_path, locale)?;
80+
81+
let output = Output::<()> {
82+
status: Status::Successful,
83+
message: Some("ran checkstyle".to_string()),
84+
result: OutputResult::ExecutedCommand,
85+
percent_done: 1.0,
86+
data: None,
87+
};
88+
print_output(&output)?
8089
} else if let Some(matches) = matches.subcommand_matches("compress-project") {
8190
let exercise_path = matches.value_of("exercise-path").unwrap();
8291
let exercise_path = Path::new(exercise_path);
@@ -97,6 +106,19 @@ fn run() -> Result<()> {
97106
output_path.display()
98107
)
99108
})?;
109+
110+
let output = Output::<()> {
111+
status: Status::Successful,
112+
message: Some(format!(
113+
"compressed project from {} to {}",
114+
exercise_path.display(),
115+
output_path.display()
116+
)),
117+
result: OutputResult::ExecutedCommand,
118+
percent_done: 1.0,
119+
data: None,
120+
};
121+
print_output(&output)?
100122
} else if let Some(matches) = matches.subcommand_matches("extract-project") {
101123
let archive_path = matches.value_of("archive-path").unwrap();
102124
let archive_path = Path::new(archive_path);
@@ -106,6 +128,19 @@ fn run() -> Result<()> {
106128

107129
task_executor::extract_project(archive_path, output_path)
108130
.with_context(|| format!("Failed to extract project at {}", output_path.display()))?;
131+
132+
let output = Output::<()> {
133+
status: Status::Successful,
134+
message: Some(format!(
135+
"extracted project from {} to {}",
136+
archive_path.display(),
137+
output_path.display()
138+
)),
139+
result: OutputResult::ExecutedCommand,
140+
percent_done: 1.0,
141+
data: None,
142+
};
143+
print_output(&output)?
109144
} else if let Some(matches) = matches.subcommand_matches("prepare-solutions") {
110145
let exercise_path = matches.value_of("exercise-path").unwrap();
111146
let exercise_path = Path::new(exercise_path);
@@ -120,6 +155,19 @@ fn run() -> Result<()> {
120155
exercise_path.display(),
121156
)
122157
})?;
158+
159+
let output = Output::<()> {
160+
status: Status::Successful,
161+
message: Some(format!(
162+
"prepared solutions for {} at {}",
163+
exercise_path.display(),
164+
output_path.display()
165+
)),
166+
result: OutputResult::ExecutedCommand,
167+
percent_done: 1.0,
168+
data: None,
169+
};
170+
print_output(&output)?
123171
} else if let Some(matches) = matches.subcommand_matches("prepare-stubs") {
124172
let exercise_path = matches.value_of("exercise-path").unwrap();
125173
let exercise_path = Path::new(exercise_path);
@@ -135,6 +183,19 @@ fn run() -> Result<()> {
135183
exercise_path.display(),
136184
)
137185
})?;
186+
187+
let output = Output::<()> {
188+
status: Status::Successful,
189+
message: Some(format!(
190+
"prepared stubs for {} at {}",
191+
exercise_path.display(),
192+
output_path.display()
193+
)),
194+
result: OutputResult::ExecutedCommand,
195+
percent_done: 1.0,
196+
data: None,
197+
};
198+
print_output(&output)?
138199
} else if let Some(matches) = matches.subcommand_matches("prepare-submission") {
139200
let submission_path = matches.value_of("submission-path").unwrap();
140201
let submission_path = Path::new(submission_path);
@@ -191,6 +252,19 @@ fn run() -> Result<()> {
191252
stub_zip_path,
192253
output_zip,
193254
)?;
255+
256+
let output = Output::<()> {
257+
status: Status::Successful,
258+
message: Some(format!(
259+
"prepared submission for {} at {}",
260+
submission_path.display(),
261+
output_path.display()
262+
)),
263+
result: OutputResult::ExecutedCommand,
264+
percent_done: 1.0,
265+
data: None,
266+
};
267+
print_output(&output)?
194268
} else if let Some(matches) = matches.subcommand_matches("run-tests") {
195269
let exercise_path = matches.value_of("exercise-path").unwrap();
196270
let exercise_path = Path::new(exercise_path);
@@ -216,6 +290,15 @@ fn run() -> Result<()> {
216290

217291
run_checkstyle(exercise_path, checkstyle_output_path, locale)?;
218292
}
293+
294+
let output = Output {
295+
status: Status::Successful,
296+
message: Some(format!("ran tests for {}", exercise_path.display(),)),
297+
result: OutputResult::ExecutedCommand,
298+
percent_done: 1.0,
299+
data: Some(test_result),
300+
};
301+
print_output(&output)?
219302
} else if let Some(matches) = matches.subcommand_matches("scan-exercise") {
220303
let exercise_path = matches.value_of("exercise-path").unwrap();
221304
let exercise_path = Path::new(exercise_path);
@@ -241,6 +324,15 @@ fn run() -> Result<()> {
241324
.with_context(|| format!("Failed to scan exercise at {}", exercise_path.display()))?;
242325

243326
write_result_to_file_as_json(&scan_result, output_path)?;
327+
328+
let output = Output {
329+
status: Status::Successful,
330+
message: Some(format!("scanned exercise at {}", exercise_path.display(),)),
331+
result: OutputResult::ExecutedCommand,
332+
percent_done: 1.0,
333+
data: Some(scan_result),
334+
};
335+
print_output(&output)?
244336
} else if let Some(matches) = matches.subcommand_matches("find-exercises") {
245337
let exercise_path = matches.value_of("exercise-path").unwrap();
246338
let exercise_path = Path::new(exercise_path);
@@ -265,6 +357,15 @@ fn run() -> Result<()> {
265357
}
266358

267359
write_result_to_file_as_json(&exercises, output_path)?;
360+
361+
let output = Output {
362+
status: Status::Successful,
363+
message: Some(format!("found exercises at {}", exercise_path.display(),)),
364+
result: OutputResult::ExecutedCommand,
365+
percent_done: 1.0,
366+
data: Some(exercises),
367+
};
368+
print_output(&output)?
268369
} else if let Some(matches) = matches.subcommand_matches("get-exercise-packaging-configuration")
269370
{
270371
let exercise_path = matches.value_of("exercise-path").unwrap();
@@ -282,12 +383,33 @@ fn run() -> Result<()> {
282383
})?;
283384

284385
write_result_to_file_as_json(&config, output_path)?;
386+
387+
let output = Output {
388+
status: Status::Successful,
389+
message: Some(format!(
390+
"created exercise packaging config from {}",
391+
exercise_path.display(),
392+
)),
393+
result: OutputResult::ExecutedCommand,
394+
percent_done: 1.0,
395+
data: Some(config),
396+
};
397+
print_output(&output)?
285398
} else if let Some(matches) = matches.subcommand_matches("clean") {
286399
let exercise_path = matches.value_of("exercise-path").unwrap();
287400
let exercise_path = Path::new(exercise_path);
288401

289402
task_executor::clean(exercise_path)
290403
.with_context(|| format!("Failed to clean exercise at {}", exercise_path.display(),))?;
404+
405+
let output = Output::<()> {
406+
status: Status::Successful,
407+
message: Some(format!("cleaned exercise at {}", exercise_path.display(),)),
408+
result: OutputResult::ExecutedCommand,
409+
percent_done: 1.0,
410+
data: None,
411+
};
412+
print_output(&output)?
291413
}
292414

293415
// core

0 commit comments

Comments
 (0)