use crate::{Error, Project, Recipe, Service};
use clap::ArgMatches;
use tracing::{info, instrument};
#[instrument(skip(subcommand))]
pub fn new(project_path: &str, subcommand: &ArgMatches) -> Result<(), Error> {
info!("Create new resource");
let project = Project::from_path(project_path)?;
let rtype = subcommand.value_of("type").expect("missing type");
let name = subcommand.value_of("name").expect("missing name");
let template = subcommand.value_of("template");
match rtype {
"service" => Service::create(project, name, template),
"recipe" => Recipe::create(project, name),
_ => Err(Error::CreateError(
"incorrect resource type",
rtype.to_string(),
)),
}
}