anticipate_runner/
lib.rs

1//! Parser and interpreter for anticipate script automation.
2#![deny(missing_docs)]
3#![forbid(unsafe_code)]
4
5mod error;
6mod interpreter;
7mod parser;
8
9pub use error::Error;
10pub use interpreter::{CinemaOptions, InterpreterOptions, ScriptFile};
11pub use parser::*;
12
13/// Result type for the parser.
14pub type Result<T> = std::result::Result<T, Error>;
15
16use std::{
17    borrow::Cow,
18    path::{Path, PathBuf},
19};
20
21/// Resolve a possibly relative path.
22pub(crate) fn resolve_path(
23    base: impl AsRef<Path>,
24    input: &str,
25) -> Result<Cow<str>> {
26    let path = PathBuf::from(input);
27    if path.is_relative() {
28        if let Some(parent) = base.as_ref().parent() {
29            let new_path = parent.join(input);
30            let path = new_path.canonicalize()?;
31            Ok(Cow::Owned(path.to_string_lossy().as_ref().to_owned()))
32        } else {
33            Ok(Cow::Borrowed(input))
34        }
35    } else {
36        Ok(Cow::Borrowed(input))
37    }
38}