mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-05-12 01:06:08 +02:00
Compare commits
4 Commits
12504b01e9
...
89e0f64279
Author | SHA1 | Date | |
---|---|---|---|
mo8it | 89e0f64279 | ||
mo8it | edea76b5b9 | ||
mo8it | 016e6a014e | ||
mo8it | cdeb8ce229 |
|
@ -649,7 +649,7 @@ checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56"
|
|||
|
||||
[[package]]
|
||||
name = "rustlings"
|
||||
version = "6.0.0-beta.4"
|
||||
version = "6.0.0-beta.5"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"assert_cmd",
|
||||
|
@ -668,7 +668,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "rustlings-macros"
|
||||
version = "6.0.0-beta.4"
|
||||
version = "6.0.0-beta.5"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"serde",
|
||||
|
@ -704,18 +704,18 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
|
|||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.198"
|
||||
version = "1.0.199"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc"
|
||||
checksum = "0c9f6e76df036c77cd94996771fb40db98187f096dd0b9af39c6c6e452ba966a"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.198"
|
||||
version = "1.0.199"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9"
|
||||
checksum = "11bd257a6541e141e42ca6d24ae26f7714887b47e89aa739099104c7e4d3b7fc"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
|
@ -8,7 +8,7 @@ exclude = [
|
|||
]
|
||||
|
||||
[workspace.package]
|
||||
version = "6.0.0-beta.4"
|
||||
version = "6.0.0-beta.5"
|
||||
authors = [
|
||||
"Liv <mokou@fastmail.com>",
|
||||
"Mo Bitar <mo8it@proton.me>",
|
||||
|
@ -20,7 +20,7 @@ license = "MIT"
|
|||
edition = "2021"
|
||||
|
||||
[workspace.dependencies]
|
||||
serde = { version = "1.0.198", features = ["derive"] }
|
||||
serde = { version = "1.0.199", features = ["derive"] }
|
||||
toml_edit = { version = "0.22.12", default-features = false, features = ["parse", "serde"] }
|
||||
|
||||
[package]
|
||||
|
@ -54,7 +54,7 @@ hashbrown = "0.14.3"
|
|||
notify-debouncer-mini = { version = "0.4.1", default-features = false }
|
||||
os_pipe = "1.1.5"
|
||||
ratatui = { version = "0.26.2", default-features = false, features = ["crossterm"] }
|
||||
rustlings-macros = { path = "rustlings-macros", version = "=6.0.0-beta.4" }
|
||||
rustlings-macros = { path = "rustlings-macros", version = "=6.0.0-beta.5" }
|
||||
serde_json = "1.0.116"
|
||||
serde.workspace = true
|
||||
toml_edit.workspace = true
|
||||
|
|
|
@ -35,7 +35,7 @@ The following command will download and compile Rustlings:
|
|||
<!-- TODO: Remove @6.0.0-beta.x -->
|
||||
|
||||
```bash
|
||||
cargo install rustlings@6.0.0-beta.4
|
||||
cargo install rustlings@6.0.0-beta.5
|
||||
```
|
||||
|
||||
<details>
|
||||
|
@ -44,7 +44,7 @@ cargo install rustlings@6.0.0-beta.4
|
|||
<!-- TODO: Remove @6.0.0-beta.x -->
|
||||
|
||||
- Make sure you have the latest Rust version by running `rustup update`
|
||||
- Try adding the `--locked` flag: `cargo install rustlings@6.0.0-beta.4 --locked`
|
||||
- Try adding the `--locked` flag: `cargo install rustlings@6.0.0-beta.5 --locked`
|
||||
- Otherwise, please [report the issue](https://github.com/rust-lang/rustlings/issues/new)
|
||||
|
||||
</details>
|
||||
|
|
|
@ -4,6 +4,7 @@ use crossterm::{
|
|||
terminal::{Clear, ClearType},
|
||||
ExecutableCommand,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use std::{
|
||||
fs::{self, File},
|
||||
io::{Read, StdoutLock, Write},
|
||||
|
@ -32,6 +33,11 @@ pub enum StateFileStatus {
|
|||
NotRead,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct CargoMetadata {
|
||||
target_directory: PathBuf,
|
||||
}
|
||||
|
||||
pub struct AppState {
|
||||
current_exercise_ind: usize,
|
||||
exercises: Vec<Exercise>,
|
||||
|
@ -91,8 +97,24 @@ impl AppState {
|
|||
pub fn new(
|
||||
exercise_infos: Vec<ExerciseInfo>,
|
||||
final_message: String,
|
||||
target_dir: PathBuf,
|
||||
) -> (Self, StateFileStatus) {
|
||||
) -> Result<(Self, StateFileStatus)> {
|
||||
let metadata_output = Command::new("cargo")
|
||||
.arg("metadata")
|
||||
.arg("-q")
|
||||
.arg("--format-version")
|
||||
.arg("1")
|
||||
.arg("--no-deps")
|
||||
.stdin(Stdio::null())
|
||||
.stderr(Stdio::inherit())
|
||||
.output()
|
||||
.context(CARGO_METADATA_ERR)?
|
||||
.stdout;
|
||||
let target_dir = serde_json::de::from_slice::<CargoMetadata>(&metadata_output)
|
||||
.context(
|
||||
"Failed to read the field `target_directory` from the `cargo metadata` output",
|
||||
)?
|
||||
.target_directory;
|
||||
|
||||
let exercises = exercise_infos
|
||||
.into_iter()
|
||||
.map(|mut exercise_info| {
|
||||
|
@ -134,7 +156,7 @@ impl AppState {
|
|||
|
||||
let state_file_status = slf.update_from_file();
|
||||
|
||||
(slf, state_file_status)
|
||||
Ok((slf, state_file_status))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -388,6 +410,10 @@ impl AppState {
|
|||
}
|
||||
}
|
||||
|
||||
const CARGO_METADATA_ERR: &str = "Failed to run the command `cargo metadata …`
|
||||
Did you already install Rust?
|
||||
Try running `cargo --version` to diagnose the problem.";
|
||||
|
||||
const RERUNNING_ALL_EXERCISES_MSG: &[u8] = b"
|
||||
All exercises seem to be done.
|
||||
Recompiling and running all exercises to make sure that all of them are actually done.
|
||||
|
|
32
src/main.rs
32
src/main.rs
|
@ -5,11 +5,10 @@ use crossterm::{
|
|||
terminal::{Clear, ClearType},
|
||||
ExecutableCommand,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use std::{
|
||||
io::{self, BufRead, Write},
|
||||
path::{Path, PathBuf},
|
||||
process::{exit, Command, Stdio},
|
||||
path::Path,
|
||||
process::exit,
|
||||
};
|
||||
|
||||
use self::{app_state::AppState, dev::DevCommands, info_file::InfoFile, watch::WatchExit};
|
||||
|
@ -77,11 +76,6 @@ enum Subcommands {
|
|||
Dev(DevCommands),
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct CargoMetadata {
|
||||
target_directory: PathBuf,
|
||||
}
|
||||
|
||||
fn in_official_repo() -> bool {
|
||||
Path::new("dev/rustlings-repo.txt").exists()
|
||||
}
|
||||
|
@ -93,21 +87,6 @@ fn main() -> Result<()> {
|
|||
bail!("{OLD_METHOD_ERR}");
|
||||
}
|
||||
|
||||
let metadata_output = Command::new("cargo")
|
||||
.arg("metadata")
|
||||
.arg("-q")
|
||||
.arg("--format-version")
|
||||
.arg("1")
|
||||
.arg("--no-deps")
|
||||
.stdin(Stdio::null())
|
||||
.stderr(Stdio::inherit())
|
||||
.output()
|
||||
.context(CARGO_METADATA_ERR)?
|
||||
.stdout;
|
||||
let target_dir = serde_json::de::from_slice::<CargoMetadata>(&metadata_output)
|
||||
.context("Failed to read the field `target_directory` from the `cargo metadata` output")?
|
||||
.target_directory;
|
||||
|
||||
match args.command {
|
||||
Some(Subcommands::Init) => {
|
||||
if DEBUG_PROFILE {
|
||||
|
@ -142,8 +121,7 @@ fn main() -> Result<()> {
|
|||
let (mut app_state, state_file_status) = AppState::new(
|
||||
info_file.exercises,
|
||||
info_file.final_message.unwrap_or_default(),
|
||||
target_dir,
|
||||
);
|
||||
)?;
|
||||
|
||||
if let Some(welcome_message) = info_file.welcome_message {
|
||||
match state_file_status {
|
||||
|
@ -219,10 +197,6 @@ The new method doesn't include cloning the Rustlings' repository.
|
|||
Please follow the instructions in the README:
|
||||
https://github.com/rust-lang/rustlings#getting-started";
|
||||
|
||||
const CARGO_METADATA_ERR: &str = "Failed to run the command `cargo metadata …`
|
||||
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.
|
||||
|
|
Loading…
Reference in New Issue