diff options
| author | Fuwn <[email protected]> | 2022-02-09 01:57:07 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-06-09 07:46:07 +0000 |
| commit | fc434785658a67fa46976071dced322ebb3ad3fa (patch) | |
| tree | 5a49f406673072203ed8088d0b53f439f223abbb | |
| parent | ci(release.yaml): enable on workflow_dispatch (diff) | |
| download | divina-fc434785658a67fa46976071dced322ebb3ad3fa.tar.xz divina-fc434785658a67fa46976071dced322ebb3ad3fa.zip | |
feat(cli): check before initing, no overwrite
| -rw-r--r-- | crates/divina/src/cli.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/crates/divina/src/cli.rs b/crates/divina/src/cli.rs index 5cc273e..4cbb6c7 100644 --- a/crates/divina/src/cli.rs +++ b/crates/divina/src/cli.rs @@ -1,6 +1,8 @@ // Copyright (C) 2022-2022 Fuwn <[email protected]> // SPDX-License-Identifier: GPL-3.0-only +use std::path::Path; + use structopt::clap::{App, AppSettings, Arg, SubCommand}; /// Create CLI @@ -53,8 +55,17 @@ pub fn execute(divina: &mut crate::Divina) { .unwrap_or("https://github.com/divinaland/init.git"); let path = init_matches.value_of("path").unwrap_or("."); + if Path::new("Divina.lua").exists() { + println!( + "!! could not clone init repository to '{}', a 'Divina.lua' already exists", + path + ); + + std::process::exit(1); + } + divina_git::clone(repository, &format!("./{}", path)) - .expect("!! could to clone init repository, perhaps the repository is invalid ?"); + .expect("!! could not clone init repository, perhaps the repository is invalid ?"); } ("build", Some(_build_matches)) => { divina @@ -64,7 +75,7 @@ pub fn execute(divina: &mut crate::Divina) { .link(); } ("clean", Some(_clean_matches)) => - if std::path::Path::new("out/").exists() { + if Path::new("out/").exists() { println!(":: removing directory 'out/'"); std::fs::remove_dir_all("out/") .expect("!! could not remove directory 'out/', check permissions"); |