|
| 1 | +use std::path::PathBuf; |
| 2 | + |
1 | 3 | use crate::cmd_args::Format; |
2 | 4 | use clap::Parser; |
3 | 5 | use cmd_args::CmdArgs; |
4 | | -use std::process::exit; |
5 | 6 |
|
6 | 7 | mod cmd_args; |
7 | 8 | mod common; |
8 | 9 | mod init; |
9 | 10 | mod json_generator; |
10 | 11 | mod markdown_generator; |
11 | 12 |
|
12 | | -fn main() { |
| 13 | +fn main() -> Result<(), Box<dyn std::error::Error>> { |
13 | 14 | let args = CmdArgs::parse(); |
14 | | - let current_path = std::env::current_dir().ok().unwrap(); |
| 15 | + let current_path = std::env::current_dir()?; |
15 | 16 | let input = args.input; |
16 | | - let mut files: Vec<String> = Vec::new(); |
17 | | - for path in &input { |
| 17 | + let mut files: Vec<PathBuf> = Vec::new(); |
| 18 | + for path in input { |
18 | 19 | if path.is_relative() { |
19 | | - match current_path.join(path).to_str() { |
20 | | - Some(p) => { |
21 | | - files.push(p.to_string()); |
22 | | - } |
23 | | - None => { |
24 | | - eprintln!("Error: {} is not a valid path.", path.to_str().unwrap()); |
25 | | - exit(1); |
26 | | - } |
27 | | - } |
| 20 | + files.push(current_path.join(path)); |
28 | 21 | } else { |
29 | | - match path.to_str() { |
30 | | - Some(p) => { |
31 | | - files.push(p.to_string()); |
32 | | - } |
33 | | - None => { |
34 | | - eprintln!("Error: {} is not a valid path.", path.to_str().unwrap()); |
35 | | - exit(1); |
36 | | - } |
37 | | - } |
| 22 | + files.push(path); |
38 | 23 | } |
39 | 24 | } |
40 | 25 |
|
41 | | - let analysis = init::load_workspace(files); |
42 | | - if let Some(mut analysis) = analysis { |
43 | | - let res = match args.format { |
44 | | - Format::Markdown => markdown_generator::generate_markdown( |
45 | | - &mut analysis, |
46 | | - args.output, |
47 | | - args.override_template, |
48 | | - args.mixin, |
49 | | - ), |
50 | | - Format::Json => json_generator::generate_json(&mut analysis, args.output), |
51 | | - }; |
| 26 | + let mut analysis = match init::load_workspace(files) { |
| 27 | + Some(a) => a, |
| 28 | + None => return Err("failed to load workspace".into()), |
| 29 | + }; |
52 | 30 |
|
53 | | - if let Err(err) = res { |
54 | | - eprintln!("Error: {}", err); |
55 | | - exit(1); |
56 | | - } |
57 | | - } else { |
58 | | - eprintln!("Analysis failed."); |
59 | | - exit(1); |
| 31 | + match args.format { |
| 32 | + Format::Markdown => markdown_generator::generate_markdown( |
| 33 | + &mut analysis, |
| 34 | + args.output, |
| 35 | + args.override_template, |
| 36 | + args.mixin, |
| 37 | + ), |
| 38 | + Format::Json => json_generator::generate_json(&mut analysis, args.output), |
60 | 39 | } |
61 | 40 | } |
0 commit comments