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 info;
33pub mod link;
34pub mod lint;
35pub mod list_recent;
36pub mod output;
37pub mod provenance;
38pub mod resolve_citation;
39pub mod search;
40pub mod text;
41pub mod verify;
42pub mod version;
43
44// Phase 4 / Slice 16. Compile-gated by the `citation` Cargo feature
45// (which itself enables `doiget-core/citation`).
46#[cfg(feature = "citation")]
47pub mod graph;
48
49use anyhow::{Context, Result};
50use camino::Utf8PathBuf;
51
52/// Resolve the on-disk store root.
53///
54/// Resolution order (subset of `docs/CONFIG.md` §4 — full CLI-flag /
55/// config-file resolution lands with the `config` subcommand):
56///
57/// 1. `DOIGET_STORE_ROOT` environment variable, if set and non-empty.
58/// 2. Fallback to `$HOME/papers` (POSIX) or `%USERPROFILE%\papers` (Windows).
59///
60/// The env-var hook is sufficient for both real use and integration tests
61/// — tests set `DOIGET_STORE_ROOT` to a `tempfile::TempDir` to keep the
62/// real `~/papers/` untouched.
63pub(crate) fn resolve_store_root() -> Result<Utf8PathBuf> {
64 if let Ok(s) = std::env::var("DOIGET_STORE_ROOT") {
65 if !s.is_empty() {
66 return Ok(Utf8PathBuf::from(s));
67 }
68 }
69 let home = std::env::var("HOME")
70 .or_else(|_| std::env::var("USERPROFILE"))
71 .context(
72 "could not determine home directory: \
73 neither HOME nor USERPROFILE is set, and DOIGET_STORE_ROOT was not provided",
74 )?;
75 Ok(Utf8PathBuf::from(home).join("papers"))
76}