mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-11-08 09:09:17 +01:00
Add --no-git
This commit is contained in:
parent
e93a99e19e
commit
4ce2714da1
10
src/dev.rs
10
src/dev.rs
@ -11,7 +11,11 @@ mod update;
|
|||||||
|
|
||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
pub enum DevCommands {
|
pub enum DevCommands {
|
||||||
New { path: PathBuf },
|
New {
|
||||||
|
path: PathBuf,
|
||||||
|
#[arg(long)]
|
||||||
|
no_git: bool,
|
||||||
|
},
|
||||||
Check,
|
Check,
|
||||||
Update,
|
Update,
|
||||||
}
|
}
|
||||||
@ -19,12 +23,12 @@ pub enum DevCommands {
|
|||||||
impl DevCommands {
|
impl DevCommands {
|
||||||
pub fn run(self) -> Result<()> {
|
pub fn run(self) -> Result<()> {
|
||||||
match self {
|
match self {
|
||||||
DevCommands::New { path } => {
|
DevCommands::New { path, no_git } => {
|
||||||
if DEBUG_PROFILE {
|
if DEBUG_PROFILE {
|
||||||
bail!("Disabled in the debug build");
|
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::Check => check::check(),
|
||||||
DevCommands::Update => update::update(),
|
DevCommands::Update => update::update(),
|
||||||
|
@ -26,7 +26,7 @@ where
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(path: &Path) -> Result<()> {
|
pub fn new(path: &Path, no_git: bool) -> Result<()> {
|
||||||
let dir_name = path.to_string_lossy();
|
let dir_name = path.to_string_lossy();
|
||||||
|
|
||||||
create_dir(path).with_context(|| format!("Failed to create the directory {dir_name}"))?;
|
create_dir(path).with_context(|| format!("Failed to create the directory {dir_name}"))?;
|
||||||
@ -35,11 +35,12 @@ pub fn new(path: &Path) -> Result<()> {
|
|||||||
set_current_dir(path)
|
set_current_dir(path)
|
||||||
.with_context(|| format!("Failed to set {dir_name} as the current directory"))?;
|
.with_context(|| format!("Failed to set {dir_name} as the current directory"))?;
|
||||||
|
|
||||||
if !Command::new("git")
|
if !no_git
|
||||||
.arg("init")
|
&& !Command::new("git")
|
||||||
.status()
|
.arg("init")
|
||||||
.context("Failed to run `git init`")?
|
.status()
|
||||||
.success()
|
.context("Failed to run `git init`")?
|
||||||
|
.success()
|
||||||
{
|
{
|
||||||
bail!("`git init` didn't run successfully. See the error message above");
|
bail!("`git init` didn't run successfully. See the error message above");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user