Repository navigation
Description
Labels: enhancement, tooling, developer-experience, good-first-issue
📋 Summary
Add a command-line interface (CLI) binary to enable rapid testing, debugging, and validation of JSON Logic rules without requiring WASM compilation or Java integration.
🎯 Motivation
Current workflow limitations:
- Testing requires building WASM + Java integration OR writing Rust unit tests
- Slow iteration cycle for rule development
- High barrier for non-Rust developers to test rules
- No easy way to validate rules in CI/CD pipelines
Benefits of CLI tool:
- ⚡ Instant feedback - Test rules in seconds
- 🐛 Easy debugging - Quickly validate syntax and behavior
- 📚 Living documentation - Runnable examples
- 🔄 CI/CD integration - Automated rule validation
- 🎯 Lower barrier - Anyone can test rules without Rust/Java setup
💡 Proposed Solution
CLI Commands
# Evaluate a single rule
flagd-eval eval --rule <RULE> --data <DATA> [--pretty]
# Run test suite
flagd-eval test <TEST_FILE> [--verbose]
# List available operators
flagd-eval operatorsUsage Examples
Inline evaluation:
flagd-eval eval \
--rule '{"sem_ver": [{"var": "version"}, ">=", "2.0.0"]}' \
--data '{"version": "2.1.0"}'
# Output:
# ✓ Evaluation succeeded
# Result: trueFile-based evaluation:
flagd-eval eval \
--rule @examples/rules/semver.json \
--data @examples/data/app-v2.json \
--prettyRun test suite:
flagd-eval test examples/rules/test-suite.json
# Output:
# Running: Semantic Version Tests
# ✓ Version equals exact match (12ms)
# ✓ Caret range allows minor updates (8ms)
# ✓ Fractional is deterministic (15ms)
#
# Results: 3 passed, 0 failed (35ms)List operators:
flagd-eval operators
# Output:
# Available Custom Operators:
#
# • fractional
# Percentage-based bucket assignment
# {"fractional": [{"var": "key"}, ["a", 50, "b", 50]]}
#
# • sem_ver
# Semantic version comparison
# {"sem_ver": [{"var": "version"}, ">=", "1.0.0"]}🏗️ Implementation Details
Project Structure
flagd-evaluator/
├── src/
│ ├── lib.rs # WASM library
│ ├── bin/
│ │ └── flagd-eval.rs # CLI binary (NEW)
│ ├── operators/
│ └── ...
├── examples/
│ ├── rules/ # Example rules (NEW)
│ │ ├── basic.json
│ │ ├── semver.json
│ │ ├── fractional.json
│ │ └── test-suite.json
│ ├── data/ # Example data (NEW)
│ │ ├── simple.json
│ │ └── app-v2.json
│ └── java/
└── tests/
└── cli_tests.rs # CLI integration tests (NEW)
Dependencies to Add
[lib]
crate-type = ["cdylib", "rlib"] # Add rlib
[[bin]]
name = "flagd-eval"
path = "src/bin/flagd-eval.rs"
[dependencies]
# Existing deps...
clap = { version = "4.5", features = ["derive", "cargo"] }
colored = "2.1"
[dev-dependencies]
assert_cmd = "2.0"
predicates = "3.0"Test Suite File Format
{
"name": "Semantic Version Tests",
"tests": [
{
"description": "Version equals exact match",
"rule": {"sem_ver": [{"var": "version"}, "=", "1.2.3"]},
"data": {"version": "1.2.3"},
"expected": true
},
{
"description": "Fractional is deterministic",
"rule": {
"fractional": [
{"var": "userId"},
["control", 50, "treatment", 50]
]
},
"data": {"userId": "user-123"},
"expected": "control"
}
]
}✅ Acceptance Criteria
Core Functionality
- CLI binary builds successfully alongside WASM module
-
evalcommand supports inline JSON -
evalcommand supports file references with@prefix -
testcommand executes test suites with clear output -
operatorscommand lists all custom operators with descriptions - Colored output (green for success, red for errors)
Testing
- Integration tests using
assert_cmdcover all commands - Tests for inline JSON evaluation
- Tests for file-based evaluation
- Tests for test suite execution
- Tests for error handling (invalid JSON, missing files)
Documentation & Examples
- Example rule files in
examples/rules/ - Example data files in
examples/data/ - Test suite examples with multiple operators
- README updated with CLI usage section
- Installation instructions (cargo install)
CI/CD
- GitHub Actions builds CLI on Linux, macOS, Windows
- CI runs CLI integration tests
- CI validates example files work
- Release workflow includes CLI binaries for all platforms
Quality
- CLI evaluation completes in <10ms for typical rules
- WASM module size remains <500KB (unaffected by CLI)
- All clippy warnings resolved
- Formatted with
cargo fmt
📦 Deliverables
-
CLI Binary (
src/bin/flagd-eval.rs)- Argument parsing with clap
- Three subcommands: eval, test, operators
- File and inline JSON support
- Colored output
-
Example Files
examples/rules/basic.jsonexamples/rules/semver.jsonexamples/rules/fractional.jsonexamples/rules/test-suite.jsonexamples/data/simple.jsonexamples/data/app-v2.json
-
Integration Tests (
tests/cli_tests.rs)- Test all subcommands
- Test file loading
- Test error cases
- Test output formatting
-
Documentation Updates
- README Quick Start section
- CLI command reference
- Example usage patterns
- Installation guide
-
CI/CD Updates
- Build CLI in CI pipeline
- Run CLI tests
- Cross-platform builds
- Include binaries in releases
🗓️ Implementation Plan
Phase 1: Basic CLI (Week 1)
- Add clap and colored dependencies
- Implement basic CLI structure with clap derive
- Add
evalcommand with inline JSON only - Colored output for success/failure
- Basic integration tests
Phase 2: File Support (Week 1)
- Add
@file.jsonprefix support - Create example rule files
- Create example data files
- Update tests for file loading
Phase 3: Test Suite (Week 2)
- Implement
testcommand - Define test suite JSON format
- Create comprehensive test suite examples
- Add test result formatting
Phase 4: Operators Command (Week 2)
- Implement
operatorscommand - Format operator descriptions
- Include syntax examples
- Test output
Phase 5: CI/CD & Documentation (Week 2)
- Update GitHub Actions workflows
- Add cross-platform builds
- Update README with CLI sections
- Add installation instructions
- Create release with binaries
🔗 Related Issues
- Create flagd-evaluator WebAssembly library for JSON Logic evaluation #1 - Implement flagd custom operators (CLI will help test these)
📚 Resources
🤔 Open Questions
- Should we support JSON5 for more human-friendly rule files?
- Should
testcommand support glob patterns for multiple test files? - Should we add a
--watchmode for continuous testing during development? - Should we support YAML format for rules/data as alternative to JSON?
💬 Additional Context
This CLI tool will not affect the WASM module in any way - it's a completely separate binary that shares the evaluation logic. The binary target is only for development/testing convenience and won't be included in the WASM output.
The CLI will be especially valuable for:
- Frontend developers testing feature flag rules
- DevOps engineers validating configurations
- QA teams testing rule logic
- Documentation with runnable examples
Priority: Medium
Estimated Effort: 2 weeks
Type: Enhancement
📝 Notes for Implementation
When implementing, ensure:
- CLI shares core evaluation logic with WASM (via
rlib) - No duplication of operator implementations
- Error messages are user-friendly and actionable
- File paths work cross-platform (Windows, Linux, macOS)
- Examples cover all custom operators
- Performance is suitable for CI/CD use (<10ms typical evaluation)
Ready to implement? Comment below if you'd like to take this on or have questions! 🚀
Activity
aepfli commentedon Dec 1, 2025
/assign @copilot