1use std::path::{Path, PathBuf};
2
3use anyhow::Result;
4use clap::Parser;
5
6use crate::workspace::load_workspace;
7
8#[derive(Parser)]
9pub struct LicensesArgs {}
10
11pub fn run_licenses(_args: LicensesArgs) -> Result<()> {
12 const LICENSE_FILES: &[&'static str] = &["LICENSE-APACHE", "LICENSE-GPL", "LICENSE-AGPL"];
13
14 let workspace = load_workspace()?;
15
16 for member in workspace.members {
17 let crate_dir = PathBuf::from(&member);
18
19 if let Some(license_file) = first_license_file(&crate_dir, &LICENSE_FILES) {
20 if !license_file.is_symlink() {
21 println!("{} is not a symlink", license_file.display());
22 }
23
24 continue;
25 }
26
27 println!("Missing license: {member}");
28 }
29
30 Ok(())
31}
32
33fn first_license_file(path: &Path, license_files: &[&str]) -> Option<PathBuf> {
34 for license_file in license_files {
35 let path_to_license = path.join(license_file);
36 if path_to_license.exists() {
37 return Some(path_to_license);
38 }
39 }
40
41 None
42}