H6: isolated data directory for dev and live-check instances
`--data-dir DIR` / `LUTRA_DATA_DIR` move settings, the recovery journal, the rendezvous file and the WebView2 user data folder into one directory. `--control PORT` without either uses `<temp>/lutra-control/<port>/`. The SHA-256-checked Phpactor cache stays shared from the user's data dir (`Engine::share_tools_from`). An isolated instance never forwards to or registers as the user's main instance; `rendezvous::dir()` honours `LUTRA_DATA_DIR` after `LUTRA_RENDEZVOUS_DIR`, so the CLI finds it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
e5891ddeb4
commit
ba70b0f43a
10 changed files with 418 additions and 29 deletions
|
|
@ -8,6 +8,8 @@ use std::path::PathBuf;
|
|||
pub struct Args {
|
||||
/// Port for the JSON control channel (`--control PORT`).
|
||||
pub control: Option<u16>,
|
||||
/// Isolated data directory (`--data-dir PATH`), see [`crate::datadir`].
|
||||
pub data_dir: Option<PathBuf>,
|
||||
/// Folder or file to open.
|
||||
pub path: Option<PathBuf>,
|
||||
/// `--help` was given.
|
||||
|
|
@ -17,9 +19,13 @@ pub struct Args {
|
|||
}
|
||||
|
||||
/// Usage text for `--help`.
|
||||
pub const USAGE: &str = "usage: lutra-desktop [--control PORT] [PATH]
|
||||
pub const USAGE: &str = "usage: lutra-desktop [--control PORT] [--data-dir DIR] [PATH]
|
||||
|
||||
--control PORT serve the JSON control channel on 127.0.0.1:PORT
|
||||
--control PORT serve the JSON control channel on 127.0.0.1:PORT; without
|
||||
--data-dir or LUTRA_DATA_DIR the data lives in
|
||||
<temp>/lutra-control/PORT
|
||||
--data-dir DIR keep settings, the recovery journal and webview data in
|
||||
DIR instead of the user's data (also: LUTRA_DATA_DIR)
|
||||
--version print the version
|
||||
--help print this help";
|
||||
|
||||
|
|
@ -41,8 +47,8 @@ pub fn parse_os(args: impl IntoIterator<Item = OsString>) -> Result<Args, String
|
|||
/// Parses the arguments after the program name.
|
||||
///
|
||||
/// # Errors
|
||||
/// A message for an unknown flag, a missing or invalid port, or more than one
|
||||
/// path.
|
||||
/// A message for an unknown flag, a missing or invalid port, a missing or
|
||||
/// empty data directory, or more than one path.
|
||||
pub fn parse(args: impl IntoIterator<Item = String>) -> Result<Args, String> {
|
||||
let mut parsed = Args::default();
|
||||
let mut args = args.into_iter();
|
||||
|
|
@ -51,11 +57,19 @@ pub fn parse(args: impl IntoIterator<Item = String>) -> Result<Args, String> {
|
|||
parsed.control = Some(port(value)?);
|
||||
continue;
|
||||
}
|
||||
if let Some(value) = arg.strip_prefix("--data-dir=") {
|
||||
parsed.data_dir = Some(data_dir(value)?);
|
||||
continue;
|
||||
}
|
||||
match arg.as_str() {
|
||||
"--control" => {
|
||||
let value = args.next().ok_or("--control needs a port")?;
|
||||
parsed.control = Some(port(&value)?);
|
||||
}
|
||||
"--data-dir" => {
|
||||
let value = args.next().ok_or("--data-dir needs a directory")?;
|
||||
parsed.data_dir = Some(data_dir(&value)?);
|
||||
}
|
||||
"--help" | "-h" => parsed.help = true,
|
||||
"--version" | "-V" => parsed.version = true,
|
||||
flag if flag.starts_with('-') => return Err(format!("unknown option {flag}")),
|
||||
|
|
@ -81,6 +95,17 @@ fn port(value: &str) -> Result<u16, String> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Parses a `--data-dir` value.
|
||||
///
|
||||
/// # Errors
|
||||
/// A message if the value is empty.
|
||||
fn data_dir(value: &str) -> Result<PathBuf, String> {
|
||||
if value.is_empty() {
|
||||
return Err("--data-dir needs a directory".into());
|
||||
}
|
||||
Ok(PathBuf::from(value))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
@ -98,6 +123,17 @@ mod tests {
|
|||
assert_eq!(p(&[]).unwrap(), Args::default());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_data_dir() {
|
||||
let a = p(&["--control", "7956", "--data-dir", "/tmp/iso", "x"]).unwrap();
|
||||
assert_eq!(a.data_dir, Some(PathBuf::from("/tmp/iso")));
|
||||
assert_eq!(a.path, Some(PathBuf::from("x")));
|
||||
let b = p(&["--data-dir=/tmp/other"]).unwrap();
|
||||
assert_eq!(b.data_dir, Some(PathBuf::from("/tmp/other")));
|
||||
assert!(p(&["--data-dir"]).is_err());
|
||||
assert!(p(&["--data-dir="]).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_bad_input() {
|
||||
assert!(p(&["--control"]).is_err());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue