Skip to content

Commit 37df3c3

Browse files
committed
Refactor function signatures for consistency and readability across commands, crypto, db, parser, and scanner modules. Simplified code formatting by removing unnecessary line breaks.
1 parent 62631d0 commit 37df3c3

5 files changed

Lines changed: 33 additions & 54 deletions

File tree

src-tauri/src/commands.rs

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,7 @@ pub fn compare_envs(
118118
// ── Vault management ─────────────────────────────────────────────────
119119

120120
#[tauri::command]
121-
pub fn setup_vault(
122-
state: State<'_, AppState>,
123-
master_pw: String,
124-
) -> Result<(), String> {
121+
pub fn setup_vault(state: State<'_, AppState>, master_pw: String) -> Result<(), String> {
125122
let mut vs = vault_state().lock();
126123
let (salt, password_hash) = vs.setup(&master_pw).map_err(|e| e.to_string())?;
127124

@@ -137,10 +134,7 @@ pub fn setup_vault(
137134
}
138135

139136
#[tauri::command]
140-
pub fn unlock_vault(
141-
state: State<'_, AppState>,
142-
master_pw: String,
143-
) -> Result<bool, String> {
137+
pub fn unlock_vault(state: State<'_, AppState>, master_pw: String) -> Result<bool, String> {
144138
let db = state.db.lock();
145139

146140
let salt = db
@@ -216,10 +210,7 @@ pub fn change_password(
216210
}
217211

218212
#[tauri::command]
219-
pub fn export_all(
220-
state: State<'_, AppState>,
221-
target_dir: String,
222-
) -> Result<u32, String> {
213+
pub fn export_all(state: State<'_, AppState>, target_dir: String) -> Result<u32, String> {
223214
let vs = vault_state().lock();
224215
let encryptor = vs.get_encryptor().ok_or("Vault is locked")?;
225216
let db = state.db.lock();
@@ -228,14 +219,10 @@ pub fn export_all(
228219
let mut exported = 0u32;
229220

230221
for project in &projects {
231-
let files = db
232-
.get_env_files(&project.id)
233-
.map_err(|e| e.to_string())?;
222+
let files = db.get_env_files(&project.id).map_err(|e| e.to_string())?;
234223

235224
for file in &files {
236-
let vars = db
237-
.get_env_variables(&file.id)
238-
.map_err(|e| e.to_string())?;
225+
let vars = db.get_env_variables(&file.id).map_err(|e| e.to_string())?;
239226

240227
let mut content = String::new();
241228
for var in &vars {
@@ -253,8 +240,7 @@ pub fn export_all(
253240
let out_path = std::path::Path::new(&target_dir)
254241
.join(&project.name)
255242
.join(&file.filename);
256-
std::fs::create_dir_all(out_path.parent().unwrap())
257-
.map_err(|e| e.to_string())?;
243+
std::fs::create_dir_all(out_path.parent().unwrap()).map_err(|e| e.to_string())?;
258244
std::fs::write(&out_path, &content).map_err(|e| e.to_string())?;
259245
exported += 1;
260246
}
@@ -287,10 +273,7 @@ pub fn search(
287273
// ── File watcher ─────────────────────────────────────────────────────
288274

289275
#[tauri::command]
290-
pub fn start_watcher(
291-
app: tauri::AppHandle,
292-
state: State<'_, AppState>,
293-
) -> Result<(), String> {
276+
pub fn start_watcher(app: tauri::AppHandle, state: State<'_, AppState>) -> Result<(), String> {
294277
let db = state.db.lock();
295278
let roots = db.get_roots().map_err(|e| e.to_string())?;
296279
let root_paths: Vec<String> = roots.iter().map(|r| r.path.clone()).collect();

src-tauri/src/crypto/mod.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ impl Encryptor {
4242
.hash_password(password.as_bytes(), &salt_str)
4343
.map_err(|e| CryptoError::KeyDerivationFailed(e.to_string()))?;
4444

45-
let hash_output = hash.hash.ok_or_else(|| {
46-
CryptoError::KeyDerivationFailed("No hash output".to_string())
47-
})?;
45+
let hash_output = hash
46+
.hash
47+
.ok_or_else(|| CryptoError::KeyDerivationFailed("No hash output".to_string()))?;
4848

4949
let bytes = hash_output.as_bytes();
5050
let mut key = [0u8; 32];
@@ -72,8 +72,8 @@ impl Encryptor {
7272

7373
/// Verify a password against a stored hash
7474
pub fn verify_password(password: &str, hash: &str) -> Result<bool, CryptoError> {
75-
let parsed_hash = PasswordHash::new(hash)
76-
.map_err(|e| CryptoError::KeyDerivationFailed(e.to_string()))?;
75+
let parsed_hash =
76+
PasswordHash::new(hash).map_err(|e| CryptoError::KeyDerivationFailed(e.to_string()))?;
7777
Ok(Argon2::default()
7878
.verify_password(password.as_bytes(), &parsed_hash)
7979
.is_ok())
@@ -119,10 +119,7 @@ impl VaultState {
119119
}
120120

121121
/// Set up a new vault with a master password
122-
pub fn setup(
123-
&mut self,
124-
password: &str,
125-
) -> Result<(Vec<u8>, String), CryptoError> {
122+
pub fn setup(&mut self, password: &str) -> Result<(Vec<u8>, String), CryptoError> {
126123
let salt = Encryptor::generate_salt();
127124
let key = Encryptor::derive_key(password, &salt)?;
128125
let password_hash = Encryptor::hash_password(password)?;

src-tauri/src/db/mod.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,10 @@ impl Database {
290290
"DELETE FROM env_vars WHERE file_id IN (SELECT id FROM env_files WHERE project_id = ?1)",
291291
params![project_id],
292292
)?;
293-
self.conn
294-
.execute("DELETE FROM env_files WHERE project_id = ?1", params![project_id])?;
293+
self.conn.execute(
294+
"DELETE FROM env_files WHERE project_id = ?1",
295+
params![project_id],
296+
)?;
295297
Ok(())
296298
}
297299

@@ -380,10 +382,7 @@ impl Database {
380382
if let Some(pids) = project_ids {
381383
if !pids.is_empty() {
382384
let placeholders: Vec<String> = pids.iter().map(|_| "?".to_string()).collect();
383-
sql.push_str(&format!(
384-
" AND p.id IN ({})",
385-
placeholders.join(",")
386-
));
385+
sql.push_str(&format!(" AND p.id IN ({})", placeholders.join(",")));
387386
}
388387
}
389388
if let Some(t) = tiers {
@@ -424,9 +423,9 @@ impl Database {
424423

425424
for fid in file_ids {
426425
// Get file info
427-
let mut stmt = self.conn.prepare(
428-
"SELECT id, filename, tier FROM env_files WHERE id = ?1",
429-
)?;
426+
let mut stmt = self
427+
.conn
428+
.prepare("SELECT id, filename, tier FROM env_files WHERE id = ?1")?;
430429
let file = stmt.query_row(params![fid], |row| {
431430
Ok(ComparisonFile {
432431
file_id: row.get(0)?,
@@ -453,7 +452,8 @@ impl Database {
453452
let keys: Vec<ComparisonKey> = all_keys
454453
.into_iter()
455454
.map(|key| {
456-
let presence: Vec<bool> = file_key_sets.iter().map(|ks| ks.contains(&key)).collect();
455+
let presence: Vec<bool> =
456+
file_key_sets.iter().map(|ks| ks.contains(&key)).collect();
457457
let count = presence.iter().filter(|&&p| p).count();
458458
let status = if count == file_ids.len() {
459459
"all".to_string()

src-tauri/src/parser/mod.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,7 @@ pub fn parse_env_contents(contents: &str) -> Vec<ParsedVar> {
6868
parse_single_quoted(raw_value)
6969
} else {
7070
// Unquoted: strip inline comments
71-
raw_value
72-
.split('#')
73-
.next()
74-
.unwrap_or("")
75-
.trim()
76-
.to_string()
71+
raw_value.split('#').next().unwrap_or("").trim().to_string()
7772
};
7873

7974
vars.push(ParsedVar {

src-tauri/src/scanner/mod.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ pub fn scan_root(
6060
) -> Result<ScanResult, String> {
6161
let root = Path::new(root_path);
6262
if !root.exists() || !root.is_dir() {
63-
return Err(format!("Root path does not exist or is not a directory: {}", root_path));
63+
return Err(format!(
64+
"Root path does not exist or is not a directory: {}",
65+
root_path
66+
));
6467
}
6568

6669
// Step 1: Discover projects
@@ -212,9 +215,7 @@ fn discover_projects(root: &Path) -> Vec<(PathBuf, String)> {
212215

213216
if is_marker || is_dotnet {
214217
if let Some(parent) = entry.path().parent() {
215-
projects
216-
.entry(parent.to_path_buf())
217-
.or_insert(filename);
218+
projects.entry(parent.to_path_buf()).or_insert(filename);
218219
}
219220
}
220221
}
@@ -238,7 +239,10 @@ fn find_env_files(project_path: &Path) -> Vec<PathBuf> {
238239
let name = entry.file_name().to_string_lossy().to_string();
239240
if name.starts_with(".env") && entry.file_type().map(|t| t.is_file()).unwrap_or(false) {
240241
// Skip .env.example files
241-
if name.ends_with(".example") || name.ends_with(".sample") || name.ends_with(".template") {
242+
if name.ends_with(".example")
243+
|| name.ends_with(".sample")
244+
|| name.ends_with(".template")
245+
{
242246
continue;
243247
}
244248
env_files.push(entry.path());

0 commit comments

Comments
 (0)