1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//! Manifest string parsing with explicit stdlib configuration.
//!
//! The `from_str`-family entrypoints in the parent module parse with the
//! default stdlib registration. This module hosts the variant that also
//! injects a caller-owned [`StdlibConfig`], so tests can pin behaviour such
//! as `command_available` resolution without mutating the process
//! environment.
use ;
use crate::;
use Result;
/// Parse a manifest string with an explicit environment reader and stdlib
/// configuration.
///
/// Combines the [`EnvReader`] of
/// [`crate::manifest::from_str_with_env`] with a full
/// [`StdlibConfig`], so a caller — in practice a test — can pin stdlib
/// behaviour such as `command_available` resolution without touching the
/// process environment or `PATH`. For instance,
/// [`StdlibConfig::with_path_override`] substitutes the host `PATH` the
/// helper searches.
///
/// # Errors
///
/// Returns an error if YAML parsing or Jinja evaluation fails.
///
/// # Examples
///
/// ```
/// use netsuke::{
/// ast::Recipe,
/// manifest::{EnvReadError, EnvReader, from_str_with_env_and_config},
/// stdlib::StdlibConfig,
/// };
/// use std::sync::Arc;
///
/// let reader: EnvReader = Arc::new(|name| match name {
/// "PROFILE" => Ok("release".to_owned()),
/// _ => Err(EnvReadError::NotPresent),
/// });
/// let config = StdlibConfig::from_current_dir()
/// .expect("construct stdlib config")
/// .with_path_override("");
/// let yaml = concat!(
/// "netsuke_version: 1.0.0\n",
/// "targets:\n",
/// " - name: build\n",
/// " command: echo {{ env('PROFILE') }}\n",
/// );
/// let manifest =
/// from_str_with_env_and_config(yaml, &reader, config).expect("parse manifest");
///
/// assert!(matches!(
/// &manifest.targets[0].recipe,
/// Recipe::Command { command } if command.as_single() == Some("echo release")
/// ));
/// ```