rustyphoenixcodemeta 1.1.0

This project aims to generate a `codemeta.json` file used by zenodo from the `pixi.toml` of the current project
/***************************************
	Auteur : Pierre Aubert
	Mail : pierre.aubert@lapp.in2p3.fr
	Licence : CeCILL-C
****************************************/

mod pixiconfig;
mod codemetaconfig;

use clap::Parser;
use std::path::PathBuf;

use crate::pixiconfig::{load_pixi_project, PixiConfig};
use crate::codemetaconfig::{save_codemeta_json, CodeMetaConfig};

///Program which generates the codemeta.json from a pixi.toml configuration
#[derive(Debug, Parser)]
#[command(version, about)]
struct Args {
	///Input directory from which to search pixi.toml
	#[arg(short, long, default_value = "./")]
	input: String,
	///List of keywords to describe the project
	#[arg(short, long, num_args = 1.., value_delimiter = ' ')]
	keyword: Vec<String>,
	///Date of creation of the current project (YYYY-MM-DD)
	#[arg(short, long, default_value = "2022-07-22")]
	creation_date: String,
	///Name of the output plot to create
	#[arg(short, long, default_value = "codemeta.json")]
	output: String,
}

///Create a codemeta from a pixi configuration
/// # Parameters
/// - `path_code_meta_config` : path to the code meta configuration to be created
/// - `path_pixi_config` : path to the pixi configuration to be loaded
/// - `vec_keyword` : vector of keywords to describe the current project
/// - `creation_date` : date of hte creation of the current project
fn phoenix_codemeta_from_pixi(path_code_meta_config: &PathBuf, path_pixi_config: &PathBuf, vec_keyword: &Vec<String>, creation_date: &String){
	let pixi_config: PixiConfig = match load_pixi_project(&path_pixi_config){
		Ok(config) => config,
		Err(err) => panic!("phoenix_codemeta_from_pixi : Cannot load pixi configuration '{:?}'. Error {}", path_pixi_config, err)
	};
	let code_meta_config: CodeMetaConfig = CodeMetaConfig::from(&pixi_config, vec_keyword, creation_date);
	match save_codemeta_json(&path_code_meta_config, &code_meta_config) {
		Ok(_) => {},
		Err(err) => panic!("phoenix_codemeta_from_pixi : Cannot save codemeta json file '{:?}'. Error: {}", path_code_meta_config, err)
	};
}

fn main() {
	let args = Args::parse();
	phoenix_codemeta_from_pixi(&PathBuf::from(args.output), &PathBuf::from(format!("{}/pixi.toml", args.input)), &args.keyword, &args.creation_date);
}

#[cfg(test)]
mod tests {
	use std::fs;
	use super::*;
	
	///Test save of a CodeMeta to JSON
	#[test]
	fn test_pixi_to_codemeta(){
		fs::create_dir_all("generated/").unwrap();
		phoenix_codemeta_from_pixi(&PathBuf::from("generated/codemeta_from_pixi.json"),
			&PathBuf::from("tests/test_config_pixi.toml"),
			&vec![String::from("phoenix"), String::from("png")],
			&String::from("2026-03-02"));
	}
}