Something went wrong. Try again.
my personal programming language!
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081pub mod chamak;
use std::{ assert_matches, fs, path::{Path, PathBuf}, sync::LazyLock,};
use clap::{Parser, Subcommand};
static WORKSPACE_PATH: LazyLock<PathBuf> = LazyLock::new(|| { let mut project = PathBuf::from(env!("CARGO_MANIFEST_DIR")); project.pop();
project});
static CARGO_PATH: LazyLock<&Path> = LazyLock::new(|| { let cargo = Path::new(env!("CARGO")); assert_matches!(cargo.try_exists(), Ok(true), "$CARGO binary should exist");
cargo});
#[derive(Parser)]struct Cli { #[command(subcommand)] command: Command,}
#[derive(Subcommand)]enum Command { #[command(subcommand)] Chamak(chamak::Command),}
fn ensure_directory<P: AsRef<Path>>(path: P) -> P { eprintln!("ensuring directory {} exists", path.as_ref().display());
let exists = path .as_ref() .try_exists() .expect("should be able to query existence of directory"); if !exists { fs::create_dir_all(path.as_ref()).expect("should be able to create directory"); }
path}
fn path_to_str(path: &Path) -> &str { path.to_str().expect("path should be utf-8")}
fn copy_dir_all(source: &Path, destination: &Path) -> anyhow::Result<()> { fs::create_dir_all(destination)?; for entry in fs::read_dir(source)? { let entry = entry?; let ty = entry.file_type()?; let source = entry.path(); let destination = destination.join(entry.file_name());
if ty.is_dir() { copy_dir_all(&source, &destination)?; } else { fs::copy(&source, &destination)?; } }
Ok(())}
fn main() -> anyhow::Result<()> { let cli = Cli::parse(); match cli.command { Command::Chamak(command) => chamak::handle(command)?, };
Ok(())}