Debian Codegraph @

rust/README.md

raw
1 <!--
2 SPDX-FileCopyrightText: Peter Pentchev <[email protected]>
3 SPDX-License-Identifier: BSD-2-Clause
4 -->
5
6 feature-check - query a program for supported features
7 ======================================================
8
9 The `feature-check` library helps programs obtain the list of supported
10 features from a program via various methods (e.g. running it with
11 the `--features` command-line option) and check for the presence and,
12 possibly, versions of specific features.
13
14 List a program's features
15 -------------------------
16
17 Use the default `List` mode of operation in the configuration object,
18 specify the program name and, possibly, the command-line option to use and
19 the string that the feature list line should start with:
20
21 use std::error::Error;
22
23 use feature_check::defs::{Config, Obtained};
24 use feature_check::obtain as fobtain;
25
26 fn main() -> Result<(), Box<dyn Error>> {
27 let config = Config {
28 program: "curl".to_string(),
29 option_name: "--version".to_string(),
30 ..Config::default()
31 };
32 match fobtain::obtain_features(&config)? {
33 Obtained::Failed(err) => eprintln!("Could not obtain the features: {}", err),
34 Obtained::NotSupported => eprintln!("Querying features not supported"),
35 Obtained::Features(res) => println!("{} features", res.len()),
36 };
37 Ok(())
38 }
39
40 Compare a single feature against a version number
41 -------------------------------------------------
42
43 Once the list of features has been queried, use an expression previously
44 obtained from the `expr::parse_simple()` function:
45
46 use std::error;
47
48 use feature_check::defs::{Config, Obtained};
49 use feature_check::expr::{self as fexpr, CalcResult};
50 use feature_check::obtain as fobtain;
51
52 fn main() -> Result<(), Box<dyn error::Error>> {
53 let query = "feature-check >= 0.2";
54 let expr = fexpr::parse_simple(&query)?;
55 let config = Config {
56 program: "feature-check".to_string(),
57 ..Config::default()
58 };
59 match fobtain::obtain_features(&config)? {
60 Obtained::Failed(err) => eprintln!(
61 "Could not obtain the features for {}: {}",
62 config.program, err
63 ),
64 Obtained::NotSupported => eprintln!("Querying features not supported"),
65 Obtained::Features(res) => {
66 println!("{} features", res.len());
67 match res.contains_key("feature-check") {
68 false => eprintln!("No 'feature-check' in the features list"),
69 true => match expr.get_value(&res)? {
70 CalcResult::Bool(value) => println!("{}: {}", query, value),
71 other => eprintln!("Unexpected result: {:?}", other),
72 },
73 };
74 }
75 };
76 Ok(())
77 }
78
79 For the crate's change history, see
80 the [changelog](https://gitlab.com/ppentchev/feature-check/-/blob/master/docs/changes.md)
81 file in the source distribution.