Skip to main content

holodeck_lib/commands/
command.rs

1use std::path::{Path, PathBuf};
2
3use anyhow::Result;
4
5/// Trait implemented by every holodeck subcommand.
6#[enum_dispatch::enum_dispatch]
7pub trait Command {
8    /// Execute the command.
9    ///
10    /// # Errors
11    /// Returns an error if the command fails.
12    fn execute(&self) -> Result<()>;
13}
14
15/// Build an output path by appending a suffix to a prefix path.
16///
17/// E.g. `output_path(Path::new("out/sample"), ".r1.fastq.gz")` → `out/sample.r1.fastq.gz`
18#[must_use]
19pub fn output_path(prefix: &Path, suffix: &str) -> PathBuf {
20    PathBuf::from(format!("{}{suffix}", prefix.to_string_lossy()))
21}
22
23#[cfg(test)]
24mod tests {
25    use super::*;
26
27    #[test]
28    fn test_output_path_simple() {
29        let result = output_path(Path::new("out/sample"), ".r1.fastq.gz");
30        assert_eq!(result, PathBuf::from("out/sample.r1.fastq.gz"));
31    }
32
33    #[test]
34    fn test_output_path_no_directory() {
35        let result = output_path(Path::new("prefix"), ".txt");
36        assert_eq!(result, PathBuf::from("prefix.txt"));
37    }
38}