cargo_wsinit/
options.rs

1use std::path::{Path, PathBuf};
2
3pub struct Options {
4    pub(crate) path: PathBuf,
5    pub(crate) existing_file_behaviour: FileExistsBehaviour,
6}
7
8#[derive(PartialEq)]
9pub enum FileExistsBehaviour {
10    /// If the toml file already exists, the tool will stop.
11    Halt,
12
13    /// If the toml file already exists, it will be modified.
14    Update,
15
16    /// If the toml file already exists, it will be overwritten.
17    Overwrite,
18}
19
20impl Options {
21    /// Create a new options struct for the specified path (not including the Cargo.toml file itself)
22    /// and the specified existing file behaviour.
23    pub fn new(path: &str, overwrite: FileExistsBehaviour) -> Options {
24        Options {
25            path: Path::new(path).into(),
26            existing_file_behaviour: overwrite,
27        }
28    }
29}
30
31impl FileExistsBehaviour {
32    pub(crate) fn create_new(&self) -> bool {
33        match self {
34            FileExistsBehaviour::Halt => true,
35            FileExistsBehaviour::Update => false,
36            FileExistsBehaviour::Overwrite => false,
37        }
38    }
39}