1
use std::ffi::OsStr;
2
use std::path::Path;
3

            
4
use clap::ValueEnum;
5

            
6
/// Specify the parity game file format.
7
#[derive(Clone, Copy, Debug, ValueEnum, PartialEq, Eq)]
8
pub enum ParityGameFormat {
9
    PG,
10
    VPG,
11
}
12

            
13
/// Guesses the parity game file format from the file extension, or uses a fixed format if provided.
14
pub fn guess_format_from_extension(path: &Path, format: Option<ParityGameFormat>) -> Option<ParityGameFormat> {
15
    if let Some(format) = format {
16
        return Some(format);
17
    }
18

            
19
    if path.extension() == Some(OsStr::new("pg")) {
20
        Some(ParityGameFormat::PG)
21
    } else if path.extension() == Some(OsStr::new("vpg")) || path.extension() == Some(OsStr::new("svpg")) {
22
        Some(ParityGameFormat::VPG)
23
    } else {
24
        None
25
    }
26
}