wdl_cli/inputs/origin_paths.rs
1//! The set of origin paths for each read input argument.
2//!
3//! An origin path is the associated directory for which each parsed command
4//! line argument is relative to. So, for example, arguments read in from files
5//! are relative to the directory the file lives within, whereas arguments
6//! provided on the command line are relative to the current working directory.
7//!
8//! This mechanism ensures that, when files or directories are specified as
9//! inputs, we know the prefix to join to those paths to resolve the final
10//! location of each path.
11
12use indexmap::IndexMap;
13use wdl_engine::path::EvaluationPath;
14
15/// An associated set of path origins for a set of input keys.
16///
17/// This is useful when, for example, resolving all paths within an
18/// [`Inputs`](super::Inputs) to be relative to the input file from whence they
19/// originated.
20#[derive(Debug)]
21pub enum OriginPaths {
22 /// A single origin path for all inputs.
23 Single(EvaluationPath),
24 /// A dynamic mapping of input keys to origin paths.
25 Map(IndexMap<String, EvaluationPath>),
26}
27
28impl OriginPaths {
29 /// Attempts to retrieve the origin path for an input key.
30 pub fn get(&self, key: &str) -> Option<&EvaluationPath> {
31 match self {
32 OriginPaths::Single(path) => Some(path),
33 OriginPaths::Map(paths) => paths.get(key),
34 }
35 }
36}