Skip to content

Conversation

@zhiningli
Copy link
Contributor

This PR addresses issue #24 by adding support for the --flag=value syntax in the ZLI command-line interface.

Changes:

  • tools/arg/arg_parser.cpp: Updated processLongFlag to parse = syntax, extracting flag name and value separately. Added validation to reject =value for boolean flags that don't accept values.
  • tools/arg/tests/arg_parser_test.cpp : Added 9 unit tests covering various scenarios.
  • tools/arg/tests/BUCK : Added Buck build configuration for the new tests.
  • tools/arg/CMakeLists.txt : Added CMake test configuration using gtest.
  • cli/zli.cpp : Updated usage message to document the = syntax.

Before:

zli compress --profile=u32 tmp# Error: Unknown option: --profile=u32

After:

zli compress --profile=u32 tmp# ✅ Works correctly!

Both syntaxes are now supported:

--profile=u32 (new)
--profile u32 (existing)

Test Plan:

Run unit tests with CMake:

# Configure with tests enabled
cmake -B build -DOPENZL_BUILD_TESTS=ON -DOPENZL_BUILD_CLI=ON# Build the arg parser testscmake --build build --target test_arg --config Release# Run the tests./build/tools/arg/Release/test_arg.exe   # Windows

Expected output:

$ cd C:\Users\Zhining\source\repos\openzl\openzl; .\build\tools\arg\Release\test_arg.exe
Running main() from C:\Users\Zhining\source\repos\openzl\openzl\build\_deps\googletest-src\googletest\src\gtest_main.cc
[==========] Running 9 tests from 1 test suite.
[----------] Global test environment set-up.
[----------] 9 tests from ArgParserTest
[ RUN      ] ArgParserTest.LongFlagWithEqualsSign
[       OK ] ArgParserTest.LongFlagWithEqualsSign (0 ms)
[ RUN      ] ArgParserTest.LongFlagWithSpaceSeparatedValue
[       OK ] ArgParserTest.LongFlagWithSpaceSeparatedValue (0 ms)
[ RUN      ] ArgParserTest.BothSyntaxesProduceSameResult
[       OK ] ArgParserTest.BothSyntaxesProduceSameResult (0 ms)
[ RUN      ] ArgParserTest.EqualSyntaxWithMultipleValues
[       OK ] ArgParserTest.EqualSyntaxWithMultipleValues (0 ms)
[ RUN      ] ArgParserTest.MixedSyntax
[       OK ] ArgParserTest.MixedSyntax (0 ms)
[ RUN      ] ArgParserTest.BooleanFlagWithoutValue
[       OK ] ArgParserTest.BooleanFlagWithoutValue (0 ms)
[ RUN      ] ArgParserTest.ValueContainingSpecialCharacters
[       OK ] ArgParserTest.ValueContainingSpecialCharacters (0 ms)
[ RUN      ] ArgParserTest.BooleanFlagWithEqualsValueThrows
[       OK ] ArgParserTest.BooleanFlagWithEqualsValueThrows (0 ms)
[ RUN      ] ArgParserTest.UnknownFlagWithEquals
[       OK ] ArgParserTest.UnknownFlagWithEquals (0 ms)
[----------] 9 tests from ArgParserTest (0 ms total)

[----------] Global test environment tear-down
[==========] 9 tests from 1 test suite ran. (0 ms total)
[  PASSED  ] 9 tests.
$ 
image

@zhiningli zhiningli self-assigned this Dec 23, 2025
@meta-cla meta-cla bot added the cla signed label Dec 23, 2025
@zhiningli zhiningli linked an issue Dec 23, 2025 that may be closed by this pull request
@zhiningli zhiningli force-pushed the zli-equals-syntax-support branch from e21826f to 3af33e9 Compare December 23, 2025 18:10
@meta-codesync
Copy link

meta-codesync bot commented Dec 24, 2025

@zhiningli has imported this pull request. If you are a Meta employee, you can view this in D89766246.

zhiningli added a commit to zhiningli/openzl that referenced this pull request Dec 24, 2025
…acebook#325)

Summary:
This PR addresses issue facebook#24 by adding support for the --flag=value syntax in the ZLI command-line interface.

Changes:
- Updated processLongFlag to parse = syntax, extracting flag name and value separately
- Added validation to reject =value for boolean flags that don't accept values
- Refactored duplicate error message construction into helper lambdas (formatFlagName, checkDuplicateFlag) following DRY principles
- Reduced nesting in processLongFlag using early returns for better readability
- Added 9 unit tests covering various scenarios
- Added Buck and CMake build configurations for tests
- Fixed BUCK file syntax error (missing comma) and converted to relative paths
- Updated usage message to document the = syntax

Both syntaxes are now supported:
- `--profile=u32` (new)
- `--profile u32` (existing)


Test Plan:
Run unit tests with Buck:
```
buck2 test fbcode//openzl/dev/tools/arg/tests:arg_parser_test
```

All 9 tests pass:
- LongFlagWithEqualsSign
- LongFlagWithSpaceSeparatedValue
- BothSyntaxesProduceSameResult
- EqualSyntaxWithMultipleValues
- MixedSyntax
- BooleanFlagWithoutValue
- ValueContainingSpecialCharacters
- BooleanFlagWithEqualsValueThrows
- UnknownFlagWithEquals

Differential Revision: D89766246

Pulled By: zhiningli
@zhiningli zhiningli force-pushed the zli-equals-syntax-support branch from 3af33e9 to c383a48 Compare December 24, 2025 16:46
@meta-codesync
Copy link

meta-codesync bot commented Dec 24, 2025

@zhiningli has exported this pull request. If you are a Meta employee, you can view the originating Diff in D89766246.

@zhiningli zhiningli force-pushed the zli-equals-syntax-support branch from c383a48 to 03f382b Compare February 7, 2026 21:54
zhiningli added a commit to zhiningli/openzl that referenced this pull request Feb 7, 2026
…acebook#325)

Summary:
This PR addresses issue facebook#24 by adding support for the --flag=value syntax in the ZLI command-line interface.

Changes:
- Updated processLongFlag to parse = syntax, extracting flag name and value separately
- Added validation to reject =value for boolean flags that don't accept values
- Added validation to reject empty value after = (e.g. --profile=) for flags that require a value
- Refactored duplicate error message construction into helper lambdas (formatFlagName, checkDuplicateFlag) following DRY principles
- Simplified processLongFlag control flow using early returns
- Added 10 unit tests covering various scenarios including empty = value
- Added Buck and CMake build configurations for tests
- Fixed BUCK file syntax error (missing comma) and converted to relative paths
- Updated usage message to document the = syntax

Both syntaxes are now supported:
- `--profile=u32` (new)
- `--profile u32` (existing)


Test Plan:
Run unit tests with Buck:
```
buck2 test fbcode//openzl/dev/tools/arg/tests:arg_parser_test
```

All 10 tests pass:
- LongFlagWithEqualsSign
- LongFlagWithSpaceSeparatedValue
- BothSyntaxesProduceSameResult
- EqualSyntaxWithMultipleValues
- MixedSyntax
- BooleanFlagWithoutValue
- ValueContainingSpecialCharacters
- BooleanFlagWithEqualsValueThrows
- UnknownFlagWithEquals
- EqualsWithEmptyValueThrows

Differential Revision: D89766246

Pulled By: zhiningli
zhiningli added a commit to zhiningli/openzl that referenced this pull request Feb 7, 2026
…acebook#325)

Summary:
This PR addresses issue facebook#24 by adding support for the --flag=value syntax in the ZLI command-line interface.

Changes:
- Updated processLongFlag to parse = syntax, extracting flag name and value separately
- Added validation to reject =value for boolean flags that don't accept values
- Added validation to reject empty value after = (e.g. --profile=) for flags that require a value
- Refactored duplicate error message construction into helper lambdas (formatFlagName, checkDuplicateFlag) following DRY principles
- Simplified processLongFlag control flow using early returns
- Added 10 unit tests covering various scenarios including empty = value
- Added Buck and CMake build configurations for tests
- Fixed BUCK file syntax error (missing comma) and converted to relative paths
- Updated usage message to document the = syntax

Both syntaxes are now supported:
- `--profile=u32` (new)
- `--profile u32` (existing)


Test Plan:
Run unit tests with Buck:
```
buck2 test fbcode//openzl/dev/tools/arg/tests:arg_parser_test
```

All 10 tests pass:
- LongFlagWithEqualsSign
- LongFlagWithSpaceSeparatedValue
- BothSyntaxesProduceSameResult
- EqualSyntaxWithMultipleValues
- MixedSyntax
- BooleanFlagWithoutValue
- ValueContainingSpecialCharacters
- BooleanFlagWithEqualsValueThrows
- UnknownFlagWithEquals
- EqualsWithEmptyValueThrows

Differential Revision: D89766246

Pulled By: zhiningli
@zhiningli zhiningli force-pushed the zli-equals-syntax-support branch from 03f382b to d777a1c Compare February 7, 2026 22:11
…acebook#325)

Summary:
This PR addresses issue facebook#24 by adding support for the --flag=value syntax in the ZLI command-line interface.

Changes:
- Updated processLongFlag to parse = syntax, extracting flag name and value separately
- Added validation to reject =value for boolean flags that don't accept values
- Added validation to reject empty value after = (e.g. --profile=) for flags that require a value
- Refactored duplicate error message construction into helper lambdas (formatFlagName, checkDuplicateFlag) following DRY principles
- Simplified processLongFlag control flow using early returns
- Added 10 unit tests covering various scenarios including empty = value
- Added Buck and CMake build configurations for tests
- Fixed BUCK file syntax error (missing comma) and converted to relative paths
- Updated usage message to document the = syntax

Both syntaxes are now supported:
- `--profile=u32` (new)
- `--profile u32` (existing)


Test Plan:
Run unit tests with Buck:
```
buck2 test fbcode//openzl/dev/tools/arg/tests:arg_parser_test
```

All 10 tests pass:
- LongFlagWithEqualsSign
- LongFlagWithSpaceSeparatedValue
- BothSyntaxesProduceSameResult
- EqualSyntaxWithMultipleValues
- MixedSyntax
- BooleanFlagWithoutValue
- ValueContainingSpecialCharacters
- BooleanFlagWithEqualsValueThrows
- UnknownFlagWithEquals
- EqualsWithEmptyValueThrows

Differential Revision: D89766246

Pulled By: zhiningli
@zhiningli zhiningli force-pushed the zli-equals-syntax-support branch from d777a1c to fdf7032 Compare February 10, 2026 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ZLI: support = in parameters, and better error messages

1 participant