1use std::path::PathBuf;
2
3use crate::cache::CacheConfig;
4
5#[derive(Debug, Clone)]
9pub struct AppState {
10 pub flake_text: String,
12 pub flake_path: PathBuf,
14 pub lock_file: Option<PathBuf>,
16 pub diff: bool,
18 pub no_lock: bool,
20 pub interactive: bool,
22 pub no_cache: bool,
24 pub cache_path: Option<PathBuf>,
26}
27
28impl AppState {
29 pub fn new(flake_text: String, flake_path: PathBuf) -> Self {
30 Self {
31 flake_text,
32 flake_path,
33 lock_file: None,
34 diff: false,
35 no_lock: false,
36 interactive: true,
37 no_cache: false,
38 cache_path: None,
39 }
40 }
41
42 pub fn with_diff(mut self, diff: bool) -> Self {
43 self.diff = diff;
44 self
45 }
46
47 pub fn with_no_lock(mut self, no_lock: bool) -> Self {
48 self.no_lock = no_lock;
49 self
50 }
51
52 pub fn with_interactive(mut self, interactive: bool) -> Self {
53 self.interactive = interactive;
54 self
55 }
56
57 pub fn with_lock_file(mut self, lock_file: Option<PathBuf>) -> Self {
58 self.lock_file = lock_file;
59 self
60 }
61
62 pub fn with_no_cache(mut self, no_cache: bool) -> Self {
63 self.no_cache = no_cache;
64 self
65 }
66
67 pub fn with_cache_path(mut self, cache_path: Option<PathBuf>) -> Self {
68 self.cache_path = cache_path;
69 self
70 }
71
72 pub fn cache_config(&self) -> CacheConfig {
74 if self.no_cache {
75 CacheConfig::None
76 } else if let Some(ref path) = self.cache_path {
77 CacheConfig::Custom(path.clone())
78 } else {
79 CacheConfig::Default
80 }
81 }
82}