mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-05-15 09:48:45 +00:00
Add shlex
This commit is contained in:
parent
dace3e3953
commit
b48663030b
7
Cargo.lock
generated
7
Cargo.lock
generated
@ -485,6 +485,7 @@ dependencies = [
|
|||||||
"rustlings-macros",
|
"rustlings-macros",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"shlex",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
"toml",
|
"toml",
|
||||||
]
|
]
|
||||||
@ -571,6 +572,12 @@ dependencies = [
|
|||||||
"serde_core",
|
"serde_core",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "shlex"
|
||||||
|
version = "1.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "signal-hook"
|
name = "signal-hook"
|
||||||
version = "0.3.18"
|
version = "0.3.18"
|
||||||
|
|||||||
@ -52,6 +52,7 @@ notify = "8"
|
|||||||
rustlings-macros = { path = "rustlings-macros", version = "=6.5.0" }
|
rustlings-macros = { path = "rustlings-macros", version = "=6.5.0" }
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
|
shlex = "1"
|
||||||
toml.workspace = true
|
toml.workspace = true
|
||||||
|
|
||||||
[target.'cfg(not(windows))'.dependencies]
|
[target.'cfg(not(windows))'.dependencies]
|
||||||
|
|||||||
@ -5,6 +5,7 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::{Context, Result, bail};
|
use anyhow::{Context, Result, bail};
|
||||||
|
use shlex::Shlex;
|
||||||
|
|
||||||
mod zellij;
|
mod zellij;
|
||||||
|
|
||||||
@ -34,20 +35,26 @@ pub enum Editor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Editor {
|
impl Editor {
|
||||||
pub fn new(cmd: Option<String>) -> Option<Self> {
|
pub fn new(cmd: Option<String>) -> Result<Option<Self>> {
|
||||||
if env::var_os("TERM_PROGRAM").is_some_and(|v| v == "vscode") {
|
if env::var_os("TERM_PROGRAM").is_some_and(|v| v == "vscode") {
|
||||||
return Some(Self::VSCode);
|
return Ok(Some(Self::VSCode));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(cmd) = cmd {
|
if let Some(cmd) = cmd {
|
||||||
todo!()
|
let shlex = &mut Shlex::new(&cmd);
|
||||||
|
let program = shlex.next().context("Program missing in `--edit-cmd`")?;
|
||||||
|
let args = shlex.collect();
|
||||||
|
if shlex.had_error {
|
||||||
|
bail!("Failed to parse the command in `--edit-cmd`");
|
||||||
|
}
|
||||||
|
return Ok(Some(Self::Cmd(program, args)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if env::var_os("ZELLIJ").is_some() {
|
if env::var_os("ZELLIJ").is_some() {
|
||||||
return Some(Self::Zellij(None));
|
return Ok(Some(Self::Zellij(None)));
|
||||||
}
|
}
|
||||||
|
|
||||||
None
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn open(
|
pub fn open(
|
||||||
|
|||||||
@ -60,10 +60,11 @@ fn main() -> Result<ExitCode> {
|
|||||||
bail!(FORMAT_VERSION_HIGHER_ERR);
|
bail!(FORMAT_VERSION_HIGHER_ERR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let editor = Editor::new(args.edit_cmd)?;
|
||||||
let (mut app_state, state_file_status) = AppState::new(
|
let (mut app_state, state_file_status) = AppState::new(
|
||||||
info_file.exercises,
|
info_file.exercises,
|
||||||
info_file.final_message.unwrap_or_default(),
|
info_file.final_message.unwrap_or_default(),
|
||||||
Editor::new(args.edit_cmd),
|
editor,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Show the welcome message if the state file doesn't exist yet.
|
// Show the welcome message if the state file doesn't exist yet.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user