use clap::{Parser, Subcommand}; use std::path::PathBuf; use webbuilder::{from_directory, Result}; #[derive(Parser)] #[command(author, version, about, long_about = None)] struct Cli { #[command(subcommand)] command: Commands, } #[derive(Subcommand)] enum Commands { /// Build a website from hjson configuration files Build { /// Path to the directory containing hjson configuration files #[arg(short, long)] path: PathBuf, /// Output directory for the webmeta.json file #[arg(short, long)] output: Option, /// Whether to upload the webmeta.json file to IPFS #[arg(short, long)] upload: bool, }, } fn main() -> Result<()> { // Initialize logger env_logger::init(); // Parse command line arguments let cli = Cli::parse(); // Handle commands match &cli.command { Commands::Build { path, output, upload, } => { // Create a WebBuilder instance let webbuilder = from_directory(path)?; // Print the parsed configuration println!("Parsed site configuration:"); println!(" Name: {}", webbuilder.config.name); println!(" Title: {}", webbuilder.config.title); println!(" Description: {:?}", webbuilder.config.description); println!(" URL: {:?}", webbuilder.config.url); println!( " Collections: {} items", webbuilder.config.collections.len() ); for (i, collection) in webbuilder.config.collections.iter().enumerate() { println!( " Collection {}: {:?} - {:?}", i, collection.name, collection.url ); } println!(" Pages: {} items", webbuilder.config.pages.len()); // Build the website let webmeta = webbuilder.build()?; // Save the webmeta.json file let output_path = output .clone() .unwrap_or_else(|| PathBuf::from("webmeta.json")); webmeta.save(&output_path)?; // Upload to IPFS if requested if *upload { let ipfs_hash = webbuilder.upload_to_ipfs(&output_path)?; println!("Uploaded to IPFS: {}", ipfs_hash); } println!("Website built successfully!"); println!("Output: {:?}", output_path); } } Ok(()) }