Skip to content

Conversation

@carlos-al
Copy link

No description provided.

This change introduces a global `--extensions` flag to the CLI, allowing users to enable all available Cooklang language extensions (like range values, temperature, etc.) which are disabled by default.

To support this configuration:
- Removed the global `static PARSER` in `src/util/mod.rs` to allow runtime configuration.
- Updated `Context` and `AppState` to carry an `Arc<CooklangParser>` instance.
- Refactored all parser call sites to accept the parser instance from the context.
- Updated `lib.rs` and tests to align with the new `Context` structure.
This change enables unit conversion support in `cookcli`. Previously, `cookcli` used an empty unit converter, meaning no units were recognized or converted.

Key changes:
- Embed default units (from `cooklang-rs` standard definitions) into the binary.
- Implement loading of `units.toml` from the configuration directory to allow user customization.
- Configure the `CooklangParser` with a `Converter` that includes both default and custom units.
- Refactor `Context` and `AppState` to carry the configured parser instance, removing the global static parser.
- Add `--extensions` flag to enable all Cooklang language extensions.

This fixes unit conversion in recipe scaling and shopping lists.
This change introduces two key features to `cookcli`:

1.  **Configurable Extensions**: Adds a global `--extensions` flag to enable all Cooklang language extensions (like range values, temperature, etc.). By default, extensions remain disabled to preserve existing behavior.

2.  **Custom Unit Definitions**: Adds support for loading a `units.toml` file from the configuration directory. This allows users to define custom units and conversions. Note: Default units are not loaded automatically to maintain backward compatibility with existing tests; users must provide a `units.toml` to enable unit conversion.

Implementation details:
- Removed the global `static PARSER` in `src/util/mod.rs` to allow runtime configuration.
- Updated `Context` and `AppState` to carry an `Arc<CooklangParser>` instance.
- Refactored all parser call sites (`recipe`, `pantry`, `doctor`, `shopping_list`, `server`) to use the propagated parser instance.
- Added `tests/spanish_test.rs` to verify custom unit loading.
This PR introduces two major enhancements:

1.  **Configurable Cooklang Extensions**: A new global `--extensions` flag allows enabling all Cooklang language features (like range values, temperature, etc.), which are disabled by default.

2.  **Custom Units Configuration**: Support for loading a `units.toml` file from the configuration directory (local or global). This allows users to define custom units and conversions. Note: Default units are not loaded automatically to preserve backward compatibility; users must provide a `units.toml` or rely on the `cooklang` crate's defaults if enabled.

Implementation details:
- Refactored `cookcli` to remove the global `static PARSER` in favor of passing a configured `Arc<CooklangParser>` via `Context`.
- Updated `src/main.rs` to detect and load `units.toml`.
- Updated `README.md` with documentation for both features.
- Added `tests/spanish_test.rs` to verify custom unit loading.
- Updated `Context` struct visibility in `src/main.rs` to fix compilation issues.
@carlos-al carlos-al closed this Jan 14, 2026
@carlos-al carlos-al reopened this Jan 14, 2026
@carlos-al carlos-al marked this pull request as draft January 14, 2026 09:19
@carlos-al carlos-al closed this by deleting the head repository Jan 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant