Add the format version

pull/1949/head
mo8it 5 months ago
parent 7ebc260924
commit 92777c0a44

@ -1,3 +1,5 @@
format_version = 1
welcome_message = """Is this your first time? Don't worry, Rustlings was made for beginners! We are welcome_message = """Is this your first time? Don't worry, Rustlings was made for beginners! We are
going to teach you a lot of things about Rust, but before we can get going to teach you a lot of things about Rust, but before we can get
started, here's a couple of notes about how Rustlings operates: started, here's a couple of notes about how Rustlings operates:

@ -39,6 +39,7 @@ impl ExerciseInfo {
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct InfoFile { pub struct InfoFile {
pub format_version: u8,
pub welcome_message: Option<String>, pub welcome_message: Option<String>,
pub final_message: Option<String>, pub final_message: Option<String>,
pub exercises: Vec<ExerciseInfo>, pub exercises: Vec<ExerciseInfo>,

@ -1,4 +1,4 @@
use anyhow::{Context, Result}; use anyhow::{bail, Context, Result};
use app_state::StateFileStatus; use app_state::StateFileStatus;
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand};
use crossterm::{ use crossterm::{
@ -24,6 +24,8 @@ mod watch;
use self::{app_state::AppState, dev::DevCommands, info_file::InfoFile, watch::WatchExit}; use self::{app_state::AppState, dev::DevCommands, info_file::InfoFile, watch::WatchExit};
const CURRENT_FORMAT_VERSION: u8 = 1;
/// Rustlings is a collection of small exercises to get you used to writing and reading Rust code /// Rustlings is a collection of small exercises to get you used to writing and reading Rust code
#[derive(Parser)] #[derive(Parser)]
#[command(version)] #[command(version)]
@ -66,6 +68,10 @@ fn main() -> Result<()> {
let info_file = InfoFile::parse()?; let info_file = InfoFile::parse()?;
if info_file.format_version > CURRENT_FORMAT_VERSION {
bail!(FORMAT_VERSION_HIGHER_ERR);
}
if matches!(args.command, Some(Subcommands::Init)) { if matches!(args.command, Some(Subcommands::Init)) {
init::init(&info_file.exercises).context("Initialization failed")?; init::init(&info_file.exercises).context("Initialization failed")?;
println!("{POST_INIT_MSG}"); println!("{POST_INIT_MSG}");
@ -156,6 +162,11 @@ const CARGO_NOT_FOUND_ERR: &str = "Failed to find `cargo`.
Did you already install Rust? Did you already install Rust?
Try running `cargo --version` to diagnose the problem."; Try running `cargo --version` to diagnose the problem.";
const FORMAT_VERSION_HIGHER_ERR: &str =
"The format version specified in the `info.toml` file is higher than the last one supported.
It is possible that you have an outdated version of Rustlings.
Try to install the latest Rustlings version first.";
const POST_INIT_MSG: &str = "Done initialization! const POST_INIT_MSG: &str = "Done initialization!
Run `cd rustlings` to go into the generated directory. Run `cd rustlings` to go into the generated directory.

Loading…
Cancel
Save