Skip to main content

cookcli_core/
lib.rs

1//! Recipe, shopping list, pantry and report operations for Cooklang.
2//!
3//! This crate holds the logic behind CookCLI's commands, with the CLI reduced
4//! to argument parsing and output formatting on top of it.
5//!
6//! Commands take their input as a [`RecipeSource`] or [`ConfigSource`] rather
7//! than a path, so an editor can pass an unsaved buffer. They return
8//! [`Outcome<T>`], which pairs the result with any [`Diagnostic`]s raised on
9//! the way, or a [`CoreError`] when no result could be produced.
10
11#![warn(missing_docs)]
12
13pub mod context;
14pub mod diagnostic;
15pub mod doctor;
16pub mod error;
17pub mod find;
18pub mod format;
19mod fs_atomic;
20pub mod outcome;
21pub mod pantry;
22pub mod parser;
23pub mod recipe;
24pub mod report;
25pub mod search;
26pub mod shopping_list;
27pub mod source;
28
29pub use context::{global_config_path, Context, CONFIG_DIR_ENV};
30pub use diagnostic::{Diagnostic, Location, Severity, Span};
31pub use error::CoreError;
32pub use find::{is_safe_relative_path, resolve_reference, REFERENCE_SEPARATOR};
33pub use format::{PaperSize, Style};
34pub use outcome::Outcome;
35pub use parser::{parse_recipe, parse_recipe_at, render_report, PARSER};
36
37/// The `cooklang` crate this library was built against.
38///
39/// [`parse_recipe`] returns a [`cooklang::Recipe`] and [`PARSER`] is a
40/// [`cooklang::CooklangParser`], so those types are part of this crate's public
41/// surface. Re-exporting lets consumers name them without adding their own
42/// `cooklang` dependency, which could otherwise resolve to a different
43/// version and fail to unify.
44pub use cooklang;
45
46/// The `cooklang-find` crate this library was built against.
47///
48/// [`find::get_recipe`] returns a [`cooklang_find::RecipeEntry`], so that type
49/// is part of this crate's public surface. Re-exported for the same reason as
50/// [`cooklang`] above.
51pub use cooklang_find;
52pub use source::{ConfigSource, RecipeSource};
53
54/// Convenience alias for core results.
55pub type Result<T> = std::result::Result<T, CoreError>;
56
57/// Compiles `README.md`'s example as a doctest, so the crate's front page
58/// cannot rot into something that no longer builds.
59///
60/// Exists only under `cfg(doctest)`, so it is not part of the public API and
61/// does not appear in the rendered documentation.
62#[doc = include_str!("../README.md")]
63#[cfg(doctest)]
64pub struct ReadmeDoctests;