Files
texturecraft/apps/texturecraft-cli/src/error.rs
T
FredApps bd03a0411f texturecraft-cli: follow RFC-0018 (clap, thiserror, run(args, out, err), packaged completions and man pages) (#875)
* texturecraft-cli: follow RFC-0018 (clap, thiserror, run(args, out, err), packaged completions and man pages)

Closes #866. Part of storytold/craft-contrib#95.

* fix(cli): enable clap env, and close replacement and token gaps

- Enable clap's `env` feature so TEXTURECRAFT_CONTROL_TOKEN compiles in a
  standalone `-p texturecraft-cli` release build (the FreeBSD package job).
- An inherited token no longer implies --bridge; only a command-line
  --token does.
- Compare run/bake/new outputs to the path Headless::save actually writes
  (it appends .tcraft when the extension is missing).
- Apply the same replacement rule to batch (save vs open), with --in-place.
- Build man-and-completions for the host when CARGO_BUILD_TARGET is set.
- Don't panic in the blank-token test when the environment already has a
  token.

* fix(cli): require both roots for headless mcp

AGENTS.md rule 18 says an agent entry point must refuse to start without
--automation-read-root and --automation-write-root (the --read-root /
--write-root aliases here). Headless mcp now exits 2 unless both are
set; --bridge is unchanged. The missing-CLI_DOCS diagnostic also names
the host-example env -u CARGO_BUILD_TARGET prefix already used to build it.
2026-11-28 01:01:49 +01:00

37 lines
1.4 KiB
Rust

use std::path::{Path, PathBuf};
use texturecraft_automation::AutomationError;
/// Why a subcommand failed: printed as `error: {e}`, exit 1.
#[derive(Debug, thiserror::Error)]
pub(crate) enum CliError {
#[error(transparent)]
Automation(#[from] AutomationError),
/// The engine's commands take paths as JSON text, which holds only Unicode.
#[error("{}: the path is not valid Unicode", .0.display())]
NotUnicode(PathBuf),
#[error("unknown built-in mesh `{0}`")]
UnknownBuiltin(String),
#[error("cannot read {}: {message}", path.display())]
Read { path: PathBuf, message: String },
#[error("cannot write {}: {source}", path.display())]
Write { path: PathBuf, source: std::io::Error },
#[error("{} is not JSON: {source}", path.display())]
Script { path: PathBuf, source: serde_json::Error },
#[error("the script must be a list of steps or {{\"steps\": [...]}}")]
ScriptShape,
#[error("the script's `{0}` field must be a string")]
ScriptField(&'static str),
#[error("step {index} (`{id}`) failed: {message}")]
BatchStopped { index: String, id: String, message: String },
#[error("{} is already a project", .0.display())]
AlreadyProject(PathBuf),
#[error("{0}")]
Serve(std::io::Error),
}
/// A path as the text the engine's commands take.
pub(crate) fn unicode(path: &Path) -> Result<&str, CliError> {
path.to_str().ok_or_else(|| CliError::NotUnicode(path.to_owned()))
}