doiget_cli/commands/mod.rs
1//! Subcommand implementations for the `doiget` CLI.
2//!
3//! Each module corresponds to a single `clap` subcommand declared in
4//! `main.rs`. The dispatch table in `main.rs` calls `run(...)` on the
5//! matching module. Subcommands return `anyhow::Result<()>`; any error
6//! surfaces via the CLI's top-level error reporter (stderr).
7//!
8//! ## Phase 1 surface (so far)
9//!
10//! - [`audit_log`] — `doiget audit-log --verify` recomputes the SHA-256 hash
11//! chain on the provenance log and reports any mismatches.
12//! - [`batch`] — `doiget batch <path>` multi-ref orchestrator (rate-bounded).
13//! - [`bib`] — `doiget bib <ref>` BibTeX exporter (Phase 2 starter).
14//! - [`cite`] — `doiget cite <ref>` live-resolve BibTeX (doi2bib-style).
15//! - [`config`] — `doiget config show/path/doctor`.
16//! - [`csl`] — `doiget csl <ref>` exports a stored entry as CSL JSON 1.0.
17//! - [`fetch`] — `doiget fetch <ref>` orchestrator (arXiv E2E + DOI metadata-only).
18//! - [`info`] — prints a stored entry's `Metadata` as TOML on stdout.
19//! - [`list_recent`] — prints up to N most-recently-fetched entries.
20//! - [`search`] — case-insensitive substring search over stored metadata.
21//!
22//! Other subcommands (`serve`) land in separate PRs.
23
24pub mod audit_log;
25pub mod batch;
26pub mod bib;
27pub mod capabilities;
28pub mod cite;
29pub mod config;
30pub mod csl;
31pub mod fetch;
32pub mod frontier;
33pub mod info;
34pub mod link;
35pub mod lint;
36pub mod list_recent;
37pub mod output;
38pub mod provenance;
39pub mod resolve_citation;
40pub mod search;
41pub mod source;
42pub mod tag;
43pub mod tex_source;
44pub mod text;
45pub mod verify;
46pub mod version;
47
48// Phase 4 / Slice 16. Compile-gated by the `citation` Cargo feature
49// (which itself enables `doiget-core/citation`).
50#[cfg(feature = "citation")]
51pub mod graph;
52
53use anyhow::{Context, Result};
54use camino::Utf8PathBuf;
55
56/// Resolve the on-disk store root.
57///
58/// Resolution order (subset of `docs/CONFIG.md` §4 — full CLI-flag /
59/// config-file resolution lands with the `config` subcommand):
60///
61/// 1. `DOIGET_STORE_ROOT` environment variable, if set and non-empty.
62/// 2. Fallback to `./papers` — `papers/` directly under the current working
63/// directory (#344 / ADR-0036), so fetched artifacts are visible where the
64/// user (or an LLM agent) is working rather than hidden in a far-off home
65/// directory. For a central, shared library set `DOIGET_STORE_ROOT`
66/// (e.g. `~/papers`, which also restores BiblioFetch.jl co-location —
67/// ADR-0004).
68///
69/// The env-var hook is sufficient for both real use and integration tests
70/// — tests set `DOIGET_STORE_ROOT` to a `tempfile::TempDir` to keep the
71/// real working directory untouched.
72pub(crate) fn resolve_store_root() -> Result<Utf8PathBuf> {
73 if let Ok(s) = std::env::var("DOIGET_STORE_ROOT") {
74 if !s.is_empty() {
75 return Ok(Utf8PathBuf::from(s));
76 }
77 }
78 let cwd = std::env::current_dir().context(
79 "could not determine the current working directory for the default store root \
80 (set DOIGET_STORE_ROOT to choose an explicit store location)",
81 )?;
82 Utf8PathBuf::from_path_buf(cwd)
83 .map(|d| d.join("papers"))
84 .map_err(|p| anyhow::anyhow!("current directory path is not UTF-8: {}", p.display()))
85}