Skip to content

Commit eef99db

Browse files
Adwait DeshpandeAdwait Deshpande
authored andcommitted
Release v0.1.6: embed default recipes and CLI/scan fixes
1 parent ac10ae5 commit eef99db

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "devspace-sweeper"
3-
version = "0.1.5"
3+
version = "0.1.6"
44
edition = "2021"
55
description = "Tiny cross-platform CLI that finds and safely cleans dev junk across projects"
66
authors = ["DevSpace Sweeper Contributors"]

src/recipes.rs

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ use serde::{Deserialize, Serialize};
44
use std::fs;
55
use std::path::{Path, PathBuf};
66

7+
// Embed the default recipes so the installed binary works even when the
8+
// `recipes/default.yml` file isn't present on the user's current working dir.
9+
const DEFAULT_RECIPES: &str = include_str!("../recipes/default.yml");
10+
711
#[derive(Debug, Clone, Serialize, Deserialize)]
812
pub struct RecipeFile {
913
pub rules: Vec<Rule>,
@@ -24,15 +28,30 @@ fn default_true() -> bool { true }
2428

2529
impl RecipeFile {
2630
pub fn load(path: Option<PathBuf>) -> Result<Self> {
27-
let path = match path {
28-
Some(p) => p,
29-
None => default_recipes_path(),
30-
};
31-
let content = fs::read_to_string(&path)
32-
.with_context(|| format!("Failed to read recipes at {}", path.display()))?;
33-
let rf: RecipeFile = serde_yaml::from_str(&content)
34-
.with_context(|| format!("Failed to parse YAML recipes at {}", path.display()))?;
35-
Ok(rf)
31+
match path {
32+
Some(p) => {
33+
let content = fs::read_to_string(&p)
34+
.with_context(|| format!("Failed to read recipes at {}", p.display()))?;
35+
let rf: RecipeFile = serde_yaml::from_str(&content)
36+
.with_context(|| format!("Failed to parse YAML recipes at {}", p.display()))?;
37+
Ok(rf)
38+
}
39+
None => {
40+
let local = default_recipes_path();
41+
if local.exists() {
42+
let content = fs::read_to_string(&local)
43+
.with_context(|| format!("Failed to read recipes at {}", local.display()))?;
44+
let rf: RecipeFile = serde_yaml::from_str(&content)
45+
.with_context(|| format!("Failed to parse YAML recipes at {}", local.display()))?;
46+
Ok(rf)
47+
} else {
48+
// Fallback to embedded default recipes compiled into the binary
49+
let rf: RecipeFile = serde_yaml::from_str(DEFAULT_RECIPES)
50+
.with_context(|| "Failed to parse embedded default recipes")?;
51+
Ok(rf)
52+
}
53+
}
54+
}
3655
}
3756

3857
pub fn compile_globset(&self) -> Result<GlobSet> {

0 commit comments

Comments
 (0)