Skip to content

Commit dd5264b

Browse files
dubadubclaude
andauthored
feat(shopping-list): add --pantry and --ignore-pantry flags (#340)
* docs: add design for shopping-list pantry flags Adds spec for --pantry and --ignore-pantry flags on the shopping-list command, mirroring the existing --aisle handling. * docs: add implementation plan for shopping-list pantry flags * feat(shopping-list): add --pantry and --ignore-pantry flags * refactor(shopping-list): drop unnecessary clone on args.pantry * fix(shopping-list): error on unreadable explicit --pantry path (#343) When --pantry is passed explicitly, surface read failures as errors instead of silently warning and producing an unfiltered list. Auto- discovered pantry paths still fall through silently, since absence is expected. Also remove the docs/superpowers/ planning artifacts that were inadvertently committed with the feature. Co-authored-by: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent d685eaf commit dd5264b

1 file changed

Lines changed: 26 additions & 3 deletions

File tree

src/shopping_list.rs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,18 @@ pub struct ShoppingListArgs {
9999
#[arg(short, long)]
100100
aisle: Option<Utf8PathBuf>,
101101

102+
/// Load pantry conf file
103+
#[arg(long)]
104+
pantry: Option<Utf8PathBuf>,
105+
102106
/// Don't expand referenced recipes
103107
#[arg(short, long)]
104108
ignore_references: bool,
105109

110+
/// Don't subtract pantry items from the shopping list
111+
#[arg(long)]
112+
ignore_pantry: bool,
113+
106114
/// Display only ingredient names, one per line, without amounts
107115
#[arg(long)]
108116
ingredients_only: bool,
@@ -195,8 +203,16 @@ pub fn run(ctx: &Context, args: ShoppingListArgs) -> Result<()> {
195203
Default::default()
196204
};
197205

198-
// Load pantry configuration if available
199-
let pantry_path = ctx.pantry();
206+
// Resolve pantry path: --ignore-pantry skips entirely; otherwise prefer
207+
// --pantry, falling back to ctx.pantry() auto-discovery.
208+
let explicit_pantry = args.pantry.is_some();
209+
let pantry_path = if args.ignore_pantry {
210+
tracing::debug!("Pantry ignored via --ignore-pantry");
211+
None
212+
} else {
213+
args.pantry.or_else(|| ctx.pantry())
214+
};
215+
200216
let pantry = if let Some(path) = &pantry_path {
201217
match std::fs::read_to_string(path) {
202218
Ok(content) => {
@@ -222,13 +238,20 @@ pub fn run(ctx: &Context, args: ShoppingListArgs) -> Result<()> {
222238
}
223239
pantry_conf
224240
}
241+
Err(e) if explicit_pantry => {
242+
return Err(anyhow::anyhow!(
243+
"Failed to read pantry file '{}': {}",
244+
path,
245+
e
246+
));
247+
}
225248
Err(e) => {
226249
warn!("Failed to read pantry file: {}", e);
227250
None
228251
}
229252
}
230253
} else {
231-
tracing::debug!("No pantry file found");
254+
tracing::debug!("No pantry file resolved");
232255
None
233256
};
234257

0 commit comments

Comments
 (0)