Add --no-git

This commit is contained in:
mo8it 2024-04-22 00:38:34 +02:00
parent e93a99e19e
commit 4ce2714da1
2 changed files with 14 additions and 9 deletions

View file

@ -11,7 +11,11 @@ mod update;
#[derive(Subcommand)]
pub enum DevCommands {
New { path: PathBuf },
New {
path: PathBuf,
#[arg(long)]
no_git: bool,
},
Check,
Update,
}
@ -19,12 +23,12 @@ pub enum DevCommands {
impl DevCommands {
pub fn run(self) -> Result<()> {
match self {
DevCommands::New { path } => {
DevCommands::New { path, no_git } => {
if DEBUG_PROFILE {
bail!("Disabled in the debug build");
}
new::new(&path).context(INIT_ERR)
new::new(&path, no_git).context(INIT_ERR)
}
DevCommands::Check => check::check(),
DevCommands::Update => update::update(),

View file

@ -26,7 +26,7 @@ where
Ok(())
}
pub fn new(path: &Path) -> Result<()> {
pub fn new(path: &Path, no_git: bool) -> Result<()> {
let dir_name = path.to_string_lossy();
create_dir(path).with_context(|| format!("Failed to create the directory {dir_name}"))?;
@ -35,7 +35,8 @@ pub fn new(path: &Path) -> Result<()> {
set_current_dir(path)
.with_context(|| format!("Failed to set {dir_name} as the current directory"))?;
if !Command::new("git")
if !no_git
&& !Command::new("git")
.arg("init")
.status()
.context("Failed to run `git init`")?