@@ -5,7 +5,7 @@ use clap::{ArgMatches, Command};
|
||||
|
||||
use crate::cli::CuddleCli;
|
||||
|
||||
pub fn build_command(root_cmd: Command, cli: CuddleCli) -> Command {
|
||||
pub fn build_command(root_cmd: Command, _cli: CuddleCli) -> Command {
|
||||
let mut repo_url = clap::Arg::new("repo").long("repo").short('r');
|
||||
|
||||
if let Ok(cuddle_template_url) = std::env::var("CUDDLE_TEMPLATE_URL") {
|
||||
@@ -14,7 +14,7 @@ pub fn build_command(root_cmd: Command, cli: CuddleCli) -> Command {
|
||||
repo_url = repo_url.required(true);
|
||||
}
|
||||
|
||||
let mut execute_cmd = Command::new("init")
|
||||
let execute_cmd = Command::new("init")
|
||||
.about("init bootstraps a repository from a template")
|
||||
.arg(repo_url)
|
||||
.arg(clap::Arg::new("name"))
|
||||
@@ -23,7 +23,7 @@ pub fn build_command(root_cmd: Command, cli: CuddleCli) -> Command {
|
||||
root_cmd.subcommand(execute_cmd)
|
||||
}
|
||||
|
||||
pub fn execute_init(exe_submatch: &ArgMatches, cli: CuddleCli) -> anyhow::Result<()> {
|
||||
pub fn execute_init(exe_submatch: &ArgMatches, _cli: CuddleCli) -> anyhow::Result<()> {
|
||||
let repo = exe_submatch.get_one::<String>("repo").unwrap();
|
||||
let name = exe_submatch.get_one::<String>("name");
|
||||
let path = exe_submatch.get_one::<String>("path");
|
||||
@@ -105,7 +105,7 @@ pub fn execute_init(exe_submatch: &ArgMatches, cli: CuddleCli) -> anyhow::Result
|
||||
}
|
||||
};
|
||||
|
||||
let (name, template_dir, template) = template?;
|
||||
let (_name, template_dir, _template) = template?;
|
||||
|
||||
let path = match path {
|
||||
Some(path) => path.clone(),
|
||||
@@ -118,7 +118,14 @@ pub fn execute_init(exe_submatch: &ArgMatches, cli: CuddleCli) -> anyhow::Result
|
||||
create_dir_all(&path)?;
|
||||
let dir = std::fs::read_dir(&path)?;
|
||||
if dir.count() != 0 {
|
||||
anyhow::bail!("Directory {} is not empty", &path);
|
||||
for entry in read_dir(&path)? {
|
||||
let entry = entry?;
|
||||
if entry.file_name() == ".git" {
|
||||
continue;
|
||||
} else {
|
||||
anyhow::bail!("Directory {} is not empty", &path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for entry in read_dir(template_dir)? {
|
||||
|
Reference in New Issue
Block a user