mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-19 14:00:43 +01:00
CLI: --automation-read-root / --automation-write-root for mcp and serve
The spelling the other crafting apps use; the same as --read-root / --write-root. Fixes #57.
This commit is contained in:
1 parent
3fac2b1482
commit
c4353cc8d0
3 files changed
+28
-5
No files matched your search
@@ -38,7 +38,8 @@ USAGE:
|
||||
New project; --sample bakes and applies a smart material to every texture set.
|
||||
texturecraft-cli mcp [--bridge <port>] [--token <token>] [--read-root <dir>] [--write-root <dir>]
|
||||
MCP server on stdio: headless (file access only below the roots), or bridged to
|
||||
`texturecraft --control <port>`.
|
||||
`texturecraft --control <port>`. --automation-read-root / --automation-write-root are
|
||||
the same as --read-root / --write-root (mcp and serve).
|
||||
texturecraft-cli serve [--port <port>] [--read-root <dir>] [--write-root <dir>]
|
||||
JSON lines ({\"id\",\"method\",\"params\"}) on stdio, or on 127.0.0.1:<port> with a token.
|
||||
|
||||
@@ -57,8 +58,8 @@ const SUBCOMMANDS: &[(&str, &[&str], &[&str])] = &[
|
||||
("export", &["--preset", "--format", "--padding", "--size"], &[]),
|
||||
("render", &["--size", "--view", "--camera", "--yaw", "--pitch", "--samples", "--bounces"], &["--cpu"]),
|
||||
("new", &["--resolution"], &["--sample"]),
|
||||
("mcp", &["--bridge", "--token", "--read-root", "--write-root"], &[]),
|
||||
("serve", &["--port", "--read-root", "--write-root"], &[]),
|
||||
("mcp", &["--bridge", "--token", "--read-root", "--write-root", "--automation-read-root", "--automation-write-root"], &[]),
|
||||
("serve", &["--port", "--read-root", "--write-root", "--automation-read-root", "--automation-write-root"], &[]),
|
||||
];
|
||||
|
||||
struct Args {
|
||||
@@ -367,7 +368,9 @@ fn new(a: &Args) -> R {
|
||||
}
|
||||
|
||||
fn workspace(a: &Args) -> Result<Filesystem, String> {
|
||||
let (r, w) = (a.get("--read-root").map(Path::new), a.get("--write-root").map(Path::new));
|
||||
// `--automation-*-root` is the spelling the other crafting apps use.
|
||||
let root = |k: &str| a.get(&format!("--automation-{k}")).or_else(|| a.get(&format!("--{k}"))).map(Path::new);
|
||||
let (r, w) = (root("read-root"), root("write-root"));
|
||||
if r.is_none() && w.is_none() {
|
||||
return Ok(Filesystem::Denied);
|
||||
}
|
||||
|
||||
@@ -97,6 +97,24 @@ fn info_on_a_mesh_reports_uvs() {
|
||||
let _ = std::fs::remove_dir_all(&d);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn serve_takes_the_automation_root_spelling_too() {
|
||||
use std::io::Write as _;
|
||||
let d = tmp("automation-root");
|
||||
let mut child = Command::new(env!("CARGO_BIN_EXE_texturecraft-cli"))
|
||||
.args(["serve", "--automation-write-root", p(&d)])
|
||||
.stdin(std::process::Stdio::piped())
|
||||
.stdout(std::process::Stdio::piped())
|
||||
.spawn()
|
||||
.unwrap();
|
||||
child.stdin.take().unwrap().write_all(b"{\"id\":1,\"method\":\"project.save\",\"params\":{\"path\":\"a.tcraft\"}}\n").unwrap();
|
||||
let out = child.wait_with_output().unwrap();
|
||||
let reply: Value = serde_json::from_slice(&out.stdout).unwrap();
|
||||
assert_eq!(reply["ok"], true, "{reply}");
|
||||
assert!(d.join("a.tcraft").is_file());
|
||||
let _ = std::fs::remove_dir_all(&d);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn render_writes_a_png() {
|
||||
let d = tmp("render");
|
||||
|
||||
@@ -100,7 +100,9 @@ print(call("command.run", {"id": "layer.add.fill", "params": {"color": [0.8, 0.1
|
||||
- **Headless** (default): an in-process session that starts on the material ball (1024).
|
||||
Files are reachable only below the roots given at launch, as forward-slash paths relative to
|
||||
them: `--read-root <dir>` for `project_open` / `mesh_import` / `mesh_reimport` / `bake_mesh_add`,
|
||||
`--write-root <dir>` for `project_save` / `material_save` / `textures_export` / `mesh_export`. Without roots there is no file access. `..`, absolute
|
||||
`--write-root <dir>` for `project_save` / `material_save` / `textures_export` / `mesh_export`
|
||||
(`--automation-read-root` / `--automation-write-root`, as in the other crafting apps, are the
|
||||
same flags). Without roots there is no file access. `..`, absolute
|
||||
paths, drive letters, device names and symlink or junction escapes are refused.
|
||||
- **Bridge**: `--bridge <port>` forwards to a running `texturecraft --control <port>` (token from
|
||||
`--token`, `TEXTURECRAFT_CONTROL_TOKEN` or the app's token file). The app reads and writes its
|
||||
|
||||
Reference in new issue
Block a user