use clap::{builder::styling::Style, Parser};
use pint_pkg::{
manifest::{ManifestFile, PackageKind},
new::new_pkg,
};
use std::path::PathBuf;
#[derive(Parser, Debug)]
pub struct Args {
#[arg(long)]
contract: bool,
#[arg(long)]
lib: bool,
#[arg(long)]
name: Option<String>,
path: PathBuf,
}
fn kind_from_bools(contract: bool, lib: bool) -> anyhow::Result<Option<PackageKind>> {
let opt = match (contract, lib) {
(false, false) => None,
(true, false) => Some(PackageKind::Contract),
(false, true) => Some(PackageKind::Library),
(true, true) => anyhow::bail!("must choose either `contract` or `lib`, not both"),
};
Ok(opt)
}
pub(crate) fn cmd(args: Args) -> anyhow::Result<()> {
let name = args.name;
let kind = kind_from_bools(args.contract, args.lib)?;
let opts = pint_pkg::new::Options { name, kind };
let manifest_path = new_pkg(&args.path, opts)?;
let manifest = ManifestFile::from_path(&manifest_path)?;
let bold = Style::new().bold();
println!(
" {}Created{} {} [{}] ({})",
bold.render(),
bold.render_reset(),
manifest.pkg.name,
manifest.pkg.kind,
manifest.dir().display(),
);
Ok(())
}