From 61a84a2c118af05493c86862e2eb5dbf7977a02e Mon Sep 17 00:00:00 2001 From: mo8it Date: Sun, 21 Apr 2024 23:43:49 +0200 Subject: dev init -> dev new PATH --- src/dev.rs | 8 ++--- src/dev/init.rs | 109 -------------------------------------------------------- src/dev/new.rs | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+), 113 deletions(-) delete mode 100644 src/dev/init.rs create mode 100644 src/dev/new.rs (limited to 'src') diff --git a/src/dev.rs b/src/dev.rs index f282181..a55a95e 100644 --- a/src/dev.rs +++ b/src/dev.rs @@ -4,12 +4,12 @@ use clap::Subcommand; use crate::DEBUG_PROFILE; mod check; -mod init; +mod new; mod update; #[derive(Subcommand)] pub enum DevCommands { - Init, + New { path: String }, Check, Update, } @@ -17,12 +17,12 @@ pub enum DevCommands { impl DevCommands { pub fn run(self) -> Result<()> { match self { - DevCommands::Init => { + DevCommands::New { path } => { if DEBUG_PROFILE { bail!("Disabled in the debug build"); } - init::init().context(INIT_ERR) + new::init().context(INIT_ERR) } DevCommands::Check => check::check(), DevCommands::Update => update::update(), diff --git a/src/dev/init.rs b/src/dev/init.rs deleted file mode 100644 index 3ce5055..0000000 --- a/src/dev/init.rs +++ /dev/null @@ -1,109 +0,0 @@ -use anyhow::{Context, Result}; -use std::fs::{self, create_dir}; - -use crate::CURRENT_FORMAT_VERSION; - -pub fn init() -> Result<()> { - create_dir("rustlings").context("Failed to create the directory `rustlings`")?; - - create_dir("rustlings/exercises") - .context("Failed to create the directory `rustlings/exercises`")?; - - create_dir("rustlings/solutions") - .context("Failed to create the directory `rustlings/solutions`")?; - - fs::write( - "rustlings/info.toml", - format!("{INFO_FILE_BEFORE_FORMAT_VERSION}{CURRENT_FORMAT_VERSION}{INFO_FILE_AFTER_FORMAT_VERSION}"), - ) - .context("Failed to create the file `rustlings/info.toml`")?; - - fs::write("rustlings/Cargo.toml", CARGO_TOML) - .context("Failed to create the file `rustlings/Cargo.toml`")?; - - fs::write("rustlings/.gitignore", crate::init::GITIGNORE) - .context("Failed to create the file `rustlings/.gitignore`")?; - - fs::write("rustlings/README.md", README) - .context("Failed to create the file `rustlings/README.md`")?; - - create_dir("rustlings/.vscode") - .context("Failed to create the directory `rustlings/.vscode`")?; - fs::write( - "rustlings/.vscode/extensions.json", - crate::init::VS_CODE_EXTENSIONS_JSON, - ) - .context("Failed to create the file `rustlings/.vscode/extensions.json`")?; - - println!("{INIT_DONE}"); - - Ok(()) -} - -const INFO_FILE_BEFORE_FORMAT_VERSION: &str = - "# The format version is an indicator of the compatibility of third-party exercises with the -# Rustlings program. -# The format version is not the same as the version of the Rustlings program. -# In case Rustlings makes an unavoidable breaking change to the expected format of third-party -# exercises, you would need to raise this version and adapt to the new format. -# Otherwise, the newest version of the Rustlings program won't be able to run these exercises. -format_version = "; - -const INFO_FILE_AFTER_FORMAT_VERSION: &str = r#" - -# Optional multi-line message to be shown to users when just starting with the exercises. -welcome_message = """Welcome to these third-party Rustlings exercises.""" - -# Optional multi-line message to be shown to users after finishing all exercises. -final_message = """We hope that you found the exercises helpful :D""" - -# Repeat this section for every exercise. -[[exercises]] -# Exercise name which is the exercise file name without the `.rs` extension. -name = "???" - -# Optional directory name to be provided if you want to organize exercises in directories. -# If `dir` is specified, the exercise path is `exercises/DIR/NAME.rs` -# Otherwise, the path is `exercises/NAME.rs` -# dir = "???" - -# The mode to run the exercise in. -# The mode "test" (preferred) runs the exercise's tests. -# The mode "run" only checks if the exercise compiles and runs it. -mode = "test" - -# A multi-line hint to be shown to users on request. -hint = """???""" -"#; - -const CARGO_TOML: &[u8] = - br#"# Don't edit the `bin` list manually! It is updated by `rustlings dev update` -bin = [] - -[package] -name = "rustlings" -edition = "2021" -publish = false - -[dependencies] -"#; - -const README: &str = "# Rustlings 🦀 - -Welcome to these third-party Rustlings exercises 😃 - -First, -[install Rustlings using the official instructions in the README of the Rustlings project](https://github.com/rust-lang/rustlings) ✅ - -Then, open your terminal in this directory and run `rustlings` to get started with the exercises 🚀 -"; - -const INIT_DONE: &str = r#"Initialization done! -You can start developing third-party Rustlings exercises in the `rustlings` directory :D - -If the initialization was done in a Rust project which is a Cargo workspace, you need to add the -path to the `rustlings` directory to the `workspace.exclude` list in the project's `Cargo.toml` -file. For example: - -[workspace] -exclude = ["rustlings"]"#; diff --git a/src/dev/new.rs b/src/dev/new.rs new file mode 100644 index 0000000..3ce5055 --- /dev/null +++ b/src/dev/new.rs @@ -0,0 +1,109 @@ +use anyhow::{Context, Result}; +use std::fs::{self, create_dir}; + +use crate::CURRENT_FORMAT_VERSION; + +pub fn init() -> Result<()> { + create_dir("rustlings").context("Failed to create the directory `rustlings`")?; + + create_dir("rustlings/exercises") + .context("Failed to create the directory `rustlings/exercises`")?; + + create_dir("rustlings/solutions") + .context("Failed to create the directory `rustlings/solutions`")?; + + fs::write( + "rustlings/info.toml", + format!("{INFO_FILE_BEFORE_FORMAT_VERSION}{CURRENT_FORMAT_VERSION}{INFO_FILE_AFTER_FORMAT_VERSION}"), + ) + .context("Failed to create the file `rustlings/info.toml`")?; + + fs::write("rustlings/Cargo.toml", CARGO_TOML) + .context("Failed to create the file `rustlings/Cargo.toml`")?; + + fs::write("rustlings/.gitignore", crate::init::GITIGNORE) + .context("Failed to create the file `rustlings/.gitignore`")?; + + fs::write("rustlings/README.md", README) + .context("Failed to create the file `rustlings/README.md`")?; + + create_dir("rustlings/.vscode") + .context("Failed to create the directory `rustlings/.vscode`")?; + fs::write( + "rustlings/.vscode/extensions.json", + crate::init::VS_CODE_EXTENSIONS_JSON, + ) + .context("Failed to create the file `rustlings/.vscode/extensions.json`")?; + + println!("{INIT_DONE}"); + + Ok(()) +} + +const INFO_FILE_BEFORE_FORMAT_VERSION: &str = + "# The format version is an indicator of the compatibility of third-party exercises with the +# Rustlings program. +# The format version is not the same as the version of the Rustlings program. +# In case Rustlings makes an unavoidable breaking change to the expected format of third-party +# exercises, you would need to raise this version and adapt to the new format. +# Otherwise, the newest version of the Rustlings program won't be able to run these exercises. +format_version = "; + +const INFO_FILE_AFTER_FORMAT_VERSION: &str = r#" + +# Optional multi-line message to be shown to users when just starting with the exercises. +welcome_message = """Welcome to these third-party Rustlings exercises.""" + +# Optional multi-line message to be shown to users after finishing all exercises. +final_message = """We hope that you found the exercises helpful :D""" + +# Repeat this section for every exercise. +[[exercises]] +# Exercise name which is the exercise file name without the `.rs` extension. +name = "???" + +# Optional directory name to be provided if you want to organize exercises in directories. +# If `dir` is specified, the exercise path is `exercises/DIR/NAME.rs` +# Otherwise, the path is `exercises/NAME.rs` +# dir = "???" + +# The mode to run the exercise in. +# The mode "test" (preferred) runs the exercise's tests. +# The mode "run" only checks if the exercise compiles and runs it. +mode = "test" + +# A multi-line hint to be shown to users on request. +hint = """???""" +"#; + +const CARGO_TOML: &[u8] = + br#"# Don't edit the `bin` list manually! It is updated by `rustlings dev update` +bin = [] + +[package] +name = "rustlings" +edition = "2021" +publish = false + +[dependencies] +"#; + +const README: &str = "# Rustlings 🦀 + +Welcome to these third-party Rustlings exercises 😃 + +First, +[install Rustlings using the official instructions in the README of the Rustlings project](https://github.com/rust-lang/rustlings) ✅ + +Then, open your terminal in this directory and run `rustlings` to get started with the exercises 🚀 +"; + +const INIT_DONE: &str = r#"Initialization done! +You can start developing third-party Rustlings exercises in the `rustlings` directory :D + +If the initialization was done in a Rust project which is a Cargo workspace, you need to add the +path to the `rustlings` directory to the `workspace.exclude` list in the project's `Cargo.toml` +file. For example: + +[workspace] +exclude = ["rustlings"]"#; -- cgit v1.2.3