alevin_fry/
cmd_parse_utils.rs1use crate::quant::{ResolutionStrategy, SplicedAmbiguityModel};
10use clap;
11use std::path::{Path, PathBuf};
12
13impl clap::ValueEnum for ResolutionStrategy {
14 fn value_variants<'a>() -> &'a [Self] {
15 &[
16 Self::Trivial,
17 Self::CellRangerLike,
18 Self::CellRangerLikeEm,
19 Self::ParsimonyEm,
20 Self::Parsimony,
21 Self::ParsimonyGeneEm,
22 Self::ParsimonyGene,
23 ]
24 }
25
26 fn to_possible_value(&self) -> Option<clap::builder::PossibleValue> {
27 match self {
28 Self::Trivial => Some(clap::builder::PossibleValue::new("trivial")),
29 Self::CellRangerLike => Some(clap::builder::PossibleValue::new("cr-like")),
30 Self::CellRangerLikeEm => Some(clap::builder::PossibleValue::new("cr-like-em")),
31 Self::ParsimonyEm => Some(clap::builder::PossibleValue::new("parsimony-em")),
32 Self::Parsimony => Some(clap::builder::PossibleValue::new("parsimony")),
33 Self::ParsimonyGeneEm => Some(clap::builder::PossibleValue::new("parsimony-gene-em")),
34 Self::ParsimonyGene => Some(clap::builder::PossibleValue::new("parsimony-gene")),
35 }
36 }
37}
38
39impl clap::ValueEnum for SplicedAmbiguityModel {
40 fn value_variants<'a>() -> &'a [Self] {
41 &[Self::PreferAmbiguity, Self::WinnerTakeAll]
42 }
43
44 fn to_possible_value(&self) -> Option<clap::builder::PossibleValue> {
45 match self {
46 Self::PreferAmbiguity => Some(clap::builder::PossibleValue::new("prefer-ambig")),
47 Self::WinnerTakeAll => Some(clap::builder::PossibleValue::new("winner-take-all")),
48 }
49 }
50}
51
52pub fn pathbuf_file_exists_validator(v: &str) -> Result<PathBuf, String> {
58 if !Path::new(v).exists() {
62 Err(String::from("No valid file was found at this path."))
63 } else {
64 Ok(PathBuf::from(v))
65 }
66}
67
68pub fn pathbuf_directory_exists_validator(v: &str) -> Result<PathBuf, String> {
74 if !Path::new(v).is_dir() {
75 Err(String::from("No valid directory was found at this path."))
76 } else {
77 Ok(PathBuf::from(v))
78 }
79}