cnf_lib/lib.rs
1// SPDX-License-Identifier: GPL-3.0-or-later
2// SPDX-FileCopyrightText: (C) 2023 Andreas Hartmann <hartan@7x.de>
3// This file is part of cnf-lib, available at <https://gitlab.com/hartang/rust/cnf>
4
5//! # cnf-lib - Library code for `cnf`
6//!
7//! The code contained here serves three main purposes.
8//!
9//!
10//! ## Handling environments
11//!
12//! An "environment" is anything that offers one or more "providers" (see below). All supported
13//! environments are listed in the [`Environment`] enum.
14//!
15//! It is often desirable to temporarily escape one environment for the sake of executing a single
16//! command. There are usually controlled mechanisms to perform this task. This crate aims to
17//! transparently manage the command translation necessary in order to, for example, execute `htop`
18//! inside a Toolbx container while working on the host. All of this is implemented in the
19//! [`Environment`] type and [`IsEnvironment`] trait.
20//!
21//! Take a look at the documentation and code in [`environment`] if you want to know more about this
22//! command translation.
23//!
24//!
25//! ## Handling providers
26//!
27//! A "provider" is anything that offers executable software. This includes for example the system
28//! `$PATH` (where executables are usually located and can be executed immediately), but extends to
29//! regular package managers such as `dnf`, usually requiring installation of commands before they
30//! can be executed. All supported providers are listed in the [`Provider`] enum.
31//!
32//! Providers can be searched for a command and return a list of zero or more possible candidates
33//! matching the search term. All of this is implemented in the [`Provider`] type and [`IsProvider`]
34//! trait.
35//!
36//! Take a look at the documentation and code in [`provider`] if you want to know more about this
37//! and for detailed instructions about implementing new providers.
38//!
39//!
40//! ## Handling command invocations
41//!
42//! Translating regular command lines between environments has a few pitfalls with respect to e.g.
43//! privilege escalation and correctly reading stdout/stderr. The [`CommandLine`] type provides the
44//! necessary abstractions to allow seamless command execution without having to wonder how
45//! privilege escalation in the target environment works, for example.
46
47pub mod environment;
48pub mod error;
49pub mod provider;
50#[cfg(any(test, doc))]
51pub mod test;
52pub mod util;
53
54// Quicker access to modules
55pub use environment as env;
56pub use provider as prov;
57
58pub use env::{Environment, Error as EnvironmentError, ExecutionError, IsEnvironment};
59pub use prov::{
60 Actions, Candidate, Error as ProviderError, IsProvider, Provider, Query, search_in,
61};
62pub use util::CommandLine;
63
64/// Public prelude.
65pub mod prelude {
66 pub use super::{
67 CommandLine, Environment, EnvironmentError, IsEnvironment, IsProvider, Provider,
68 ProviderError, Query, search_in,
69 };
70}