use std::path::PathBuf;
use clap::Parser;
use anyhow::Result;
use heck::AsKebabCase;
use merlon::package::Package;
#[derive(Parser, Debug)]
pub struct Args {
name: String,
}
pub fn run(dir: Option<PathBuf>, args: Args) -> Result<()> {
let current_dir = std::env::current_dir()?;
let dir = dir.unwrap_or_else(|| current_dir.join(format!("{}", AsKebabCase(&args.name))));
let package = Package::new(args.name, dir)?;
let path_relative_to_current = package.path()
.strip_prefix(current_dir)
.unwrap_or_else(|_| package.path());
println!("");
println!("Created package: {}", &package);
println!("To build and run this package, run the following commands:");
println!("");
println!(" cd {:?}", path_relative_to_current);
println!(" merlon init");
println!(" merlon run");
println!("");
Ok(())
}