Grcov report - context.rs

1

    use std::env;

2

    use std::path::PathBuf;

3

4

    pub(super) struct Context {

5

      keys_location: Option<String>,

6

      vault_location: Option<String>,

7

      key_name: Option<String>,

8

    }

9

10

    impl Context {

11

      pub fn new() -> Self {

12

        Self {

13

          keys_location: None,

14

          vault_location: None,

15

          key_name: None,

16

        }

17

      }

18

19

      pub fn set_keys_location(&mut self, keys_location: &str) {

20

        self.keys_location = Some(keys_location.to_string());

21

      }

22

23

      pub fn set_vault_location(&mut self, vault_location: &str) {

24

        self.vault_location = Some(vault_location.to_string());

25

      }

26

27

      pub fn keys_location(&self) -> String {

28

        self.keys_location.clone().unwrap_or_else(|| {

29

          let home_dir = if cfg!(target_os = "windows") {

30

            env::var("USERPROFILE").unwrap_or_else(|_| "./.mk/priv".to_string())

31

          } else {

32

            env::var("HOME").unwrap_or_else(|_| "./.mk/priv".to_string())

33

          };

34

          let mut path = PathBuf::from(home_dir);

35

          path.push(".config");

36

          path.push("mk");

37

          path.push("priv");

38

          path.to_string_lossy().to_string()

39

        })

40

      }

41

42

      pub fn vault_location(&self) -> String {

43

        self.vault_location.clone().unwrap_or("./.mk/vault".to_string())

44

      }

45

46

      pub fn key_name(&self) -> String {

47

        self.key_name.clone().unwrap_or("default".to_string())

48

      }

49

    }