leviath_cli/commands/mod.rs
1//! CLI command implementations.
2
3#[cfg(test)]
4thread_local! {
5 /// Test-only toggle letting a test force [`resolve_cwd`]'s `Err` arm
6 /// deterministically on every platform, as a companion to
7 /// `list`'s `execute_falls_back_to_default_cwd_when_current_dir_is_gone`
8 /// genuine Unix-only filesystem reproduction (real `remove_dir_all` of the
9 /// live CWD is a sharing violation on Windows, not a success, so that same
10 /// trick isn't available there).
11 static FORCE_CWD_ERROR: std::cell::Cell<bool> = const { std::cell::Cell::new(false) };
12}
13
14/// Real CWD lookup, with a test-only failure-injection toggle so its `Err`
15/// arm can be forced deterministically (see [`force_cwd_error`]) without
16/// changing what production actually calls.
17///
18/// Shared: `list` and `validate` both need the directory a command was run
19/// from, `validate` because it is the workdir a `lev run` would default to and
20/// therefore what relative `[read_paths]` entries resolve against.
21pub(crate) fn resolve_cwd() -> std::io::Result<std::path::PathBuf> {
22 #[cfg(test)]
23 if FORCE_CWD_ERROR.with(|f| f.get()) {
24 return Err(std::io::Error::other("forced CWD error for testing"));
25 }
26 std::env::current_dir()
27}
28
29/// Force (or release) [`resolve_cwd`]'s failure path for the current thread.
30#[cfg(test)]
31pub(crate) fn force_cwd_error(on: bool) {
32 FORCE_CWD_ERROR.with(|f| f.set(on));
33}
34
35pub mod add;
36pub mod agent_client;
37pub mod auth;
38pub mod context;
39pub mod create;
40pub mod ctl;
41pub mod daemon;
42pub mod daemon_service;
43pub mod dashboard;
44pub mod doctor;
45pub mod list;
46pub mod mcp;
47pub mod models;
48pub mod pack;
49pub mod policy;
50pub mod ps;
51pub mod remove;
52pub mod run;
53pub mod serve;
54pub mod setup;
55pub mod test;
56pub mod tools;
57pub mod validate;