diff options
| author | mo8it <mo8it@proton.me> | 2024-04-16 01:22:54 +0200 |
|---|---|---|
| committer | mo8it <mo8it@proton.me> | 2024-04-16 01:22:54 +0200 |
| commit | 92777c0a4498625a44c0e6eeced97633dacc78d1 (patch) | |
| tree | 37ff3eb2c40d5ac0889339890ef8d9b514a5f13f /src/main.rs | |
| parent | 7ebc260924f5db0099568589f2be621c9ea43721 (diff) | |
Add the format version
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs index e72dbdc..7d4d8a5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use anyhow::{Context, Result}; +use anyhow::{bail, Context, Result}; use app_state::StateFileStatus; use clap::{Parser, Subcommand}; use crossterm::{ @@ -24,6 +24,8 @@ mod watch; 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 #[derive(Parser)] #[command(version)] @@ -66,6 +68,10 @@ fn main() -> Result<()> { 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)) { init::init(&info_file.exercises).context("Initialization failed")?; println!("{POST_INIT_MSG}"); @@ -156,6 +162,11 @@ const CARGO_NOT_FOUND_ERR: &str = "Failed to find `cargo`. Did you already install Rust? 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! Run `cd rustlings` to go into the generated directory. |
