sneakerweb 1.0.1

A parallel web transported by physical media
use clap::Parser;

mod block;
mod commands;
mod domain;
mod export;
mod import;
mod logo;
mod publish;
mod serve;
mod util;

use commands::*;
use util::*;

fn main() {
    let cli = Cli::parse();

    match &cli.command {
        cmd => match cmd {
            Commands::Domain(domain_args) => {
                // Generate a new subspace keypair and pressent it to the user
                domain::generate_domain(domain_args);
            }
            Commands::Publish(publish_args) => {
                // Verify a domain keypair, then recurse through the given filesystem location,
                // writing entries to that domain for any files encountered.
                //
                // Skip files matching globs in ".nopublish" files, and the ".nopublish" files themselves.
                smol::block_on(async {
                    match publish::publish(publish_args).await {
                        Ok(_) => yay("publishing complete!").await,
                        Err(err) => oh_no(&format!("{}", err)).await,
                    }
                })
            }
            Commands::Block(block_args) => {
                // Forget the given subspace ID from persistent storage.
                // And add it to a blocklist, which for now could maybe just be a line delimited text file.
                smol::block_on(async {
                    match block::block(block_args).await {
                        Ok(_) => yay("domain blocked").await,
                        Err(err) => oh_no(&format! {"{}", err}).await,
                    }
                })
            }
            Commands::Import(import_args) => {
                // Import the contents of a drop into the persistent store.
                smol::block_on(async {
                    match import::import_sneak(import_args).await {
                        Ok(_) => {
                            yay(&format!(
                                "successfully imported from {}",
                                import_args.src.to_string_lossy()
                            ))
                            .await
                        }
                        Err(err) => oh_no(&format!("{}", err)).await,
                    }
                })
            }
            Commands::Export(export_args) => {
                // Export the contents of the persistent store into a willow drop.
                smol::block_on(async {
                    match export::export_sneak(export_args).await {
                        Ok(dest) => {
                            yay(&format!("sneak exported to {}", dest.to_string_lossy())).await
                        }
                        Err(err) => oh_no(&format!("{}", err)).await,
                    }
                })
            }
            &Commands::Serve => {
                smol::block_on(async {
                    match serve::start_server().await {
                        Ok(()) => (), // I don't think we have anything interesting to say when the server shuts down?
                        Err(err) => oh_no(&format!("{}", err)).await,
                    }
                });
            }
        },
    }
}