Skip to main content

Grove/Binary/
mod.rs

1//! Binary Module
2//!
3//! Contains binary-specific initialization and build logic.
4//! Used by the standalone Grove executable.
5
6pub mod Build;
7
8pub mod Main;
9
10/// Binary configuration
11#[derive(Debug, Clone)]
12pub struct BinaryConfig {
13	/// Binary name
14	pub name:String,
15
16	/// Binary version
17	pub version:String,
18
19	/// Enable verbose output
20	pub verbose:bool,
21
22	/// Enable debug mode
23	pub debug:bool,
24}
25
26impl BinaryConfig {
27	/// Create a new binary configuration
28	pub fn new() -> Self {
29		Self {
30			name:"grove".to_string(),
31
32			version:env!("CARGO_PKG_VERSION").to_string(),
33
34			verbose:false,
35
36			debug:cfg!(debug_assertions),
37		}
38	}
39
40	/// Set verbose mode
41	pub fn with_verbose(mut self, verbose:bool) -> Self {
42		self.verbose = verbose;
43
44		self
45	}
46
47	/// Set debug mode
48	pub fn with_debug(mut self, debug:bool) -> Self {
49		self.debug = debug;
50
51		self
52	}
53}
54
55impl Default for BinaryConfig {
56	fn default() -> Self { Self::new() }
57}
58
59#[cfg(test)]
60mod tests {
61
62	use super::*;
63
64	#[test]
65	fn test_binary_config_default() {
66		let config = BinaryConfig::default();
67
68		assert_eq!(config.name, "grove");
69
70		assert!(!config.verbose);
71	}
72
73	#[test]
74	fn test_binary_config_builder() {
75		let config = BinaryConfig::default().with_verbose(true).with_debug(true);
76
77		assert!(config.verbose);
78
79		assert!(config.debug);
80	}
81}