Skip to content

Commit 1ba81c2

Browse files
jdxclaudeautofix-ci[bot]
authored
feat(parse): add Parser builder for custom env var handling (#464)
## Summary - Adds a `Parser` struct that allows customizing parsing behavior - Particularly useful for providing a custom environment variable map instead of using the process environment This is needed for tools like mise where monorepo tasks may have env vars defined in child config files that aren't in the current process environment. ## Example usage ```rust use std::collections::HashMap; use usage::parse::Parser; let env: HashMap<String, String> = [("NAME".into(), "john".into())].into(); let result = Parser::new(&spec) .with_env(env) .parse(&args)?; ``` The existing `parse()` function is unchanged and continues to work as before (it now uses `Parser` internally with default options). ## API Design The `Parser` struct uses `#[non_exhaustive]` to allow adding new options in the future without breaking changes. 🤖 Generated with [Claude Code](https://claude.ai/code) <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Introduce `Parser` for customizable parsing** > > - Export new `parse::Parser` with `with_env` to supply a custom `HashMap<String, String>` for env lookups; `parse()` now delegates to `Parser` > - Refactor `parse_partial` into internal `parse_partial_with_env` and update required arg/flag validation to consider the custom env map before `std::env` > - Preserve existing behavior by default (process env) while enabling monorepo/task workflows needing non-process env vars > - Add tests covering custom env for required args/flags, precedence, and error cases > > **Public API**: `Parser` exported via `lib.rs` > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 6294833. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 6125f1f commit 1ba81c2

File tree

2 files changed

+281
-106
lines changed

2 files changed

+281
-106
lines changed

lib/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
extern crate insta;
33
extern crate log;
44

5-
pub use crate::parse::parse;
5+
pub use crate::parse::{parse, Parser};
66
pub use crate::spec::arg::SpecArg;
77
pub use crate::spec::builder::{SpecArgBuilder, SpecCommandBuilder, SpecFlagBuilder};
88
pub use crate::spec::choices::SpecChoices;

0 commit comments

Comments
 (0)