All notable changes to this project are documented below. This file follows the "Keep a Changelog" format and the project follows Semantic Versioning.
For details on the project and examples, see the repository README and the docs/ folder.
Changed
- Code Simplification: Refactored internal implementation to reduce complexity and remove duplicate code patterns without losing any functionality.
- Helper Functions: Introduced helper functions for common operations like TArgValue initialization and array management to reduce repetitive code.
- Cleaner Type Parsing: Split the complex
ParseValuemethod into focused type-specific parsing functions for better maintainability. - Simplified Tokenizer: Extracted helper functions in ArgTokenizer to improve code readability and reduce complexity.
- Streamlined Methods: Consolidated duplicate initialization patterns in
AddXXXmethods and simplified array operations throughout the codebase.
Fixed
- Improved Error Messages: Fixed misleading error messages for missing required positional arguments. Now correctly shows "Missing required positional argument: filename" instead of "Missing required option: --filename" for better user experience and consistency with CLI conventions.
Note: This release contains internal simplifications, refactoring, and improved error messaging. All public APIs remain unchanged and fully backward compatible.
Changed
- Internal Code Simplification: Removed unused internal methods
IsHelpRequested()andNormalizeToken()to reduce code complexity and improve maintainability (~80 lines of dead code removed). - Documentation Updates: Updated internal code comments to better reflect the separation of concerns between ArgParser and ArgTokenizer.
- Maintainability: All changes are internal only - no public API changes, full backward compatibility maintained.
Changed
- Code Simplification: Refactored
ArgParser.pasto reduce code duplication betweenParseCommandLineandParseCommandLineKnownby extracting common--separator logic into a shared helper methodSplitArgsAroundSeparator. - Code Cleanup: Removed redundant
ParseKnownwrapper method that only delegated toParseKnownArgs. - ArgTokenizer Improvement: Extracted PowerShell quirk handling (appending tokens starting with '.') into a reusable helper function
AppendDotTokenIfPresentto eliminate code duplication. - Maintainability: No functional changes - all existing behavior preserved while making the codebase cleaner and easier to maintain.
Added
ArgTokenizer.pas: Added explanatory comments toTokenizeArgsdescribing the combined-short splitting heuristic (small all-alpha groups <= 3 are split) and the PowerShell dot-join quirk where a following token beginning with '.' is reattached for short-inline values.ArgParser.pas: Introduced a per-parser configuration fieldFSplitCombinedShorts(initialized from the legacy module-globalSplitCombinedShorts) so callers can control combined-short splitting on a per-instance basis.ArgParser.pas: AddedSetAllowMultiple(const LongOpt: string; const Value: Boolean)helper to enable accumulation behavior for repeated options.- Tests: Added and updated tokenizer and parser unit tests covering combined-shorts, short-inline values, PowerShell '.' reattachment, single
-and negative-number handling,--name=valuesplitting,--separator leftovers, and accumulation of repeated options.
Changed
ArgParser.pas: Calls to the tokenizer temporarily set the module-globalSplitCombinedShortsfrom the parser instance field and restore it afterwards to preserve backward compatibility while enabling per-instance control.
Notes
Default behavior is unchanged: combined-short splitting remains enabled by default. Callers who
need conservative behavior can set FSplitCombinedShorts to False on their TArgParser instance.
Documentation: help output is documented to show that ShowHelp appends " (required)" to any
option or positional marked as required.
Added / Changed
- Extracted tokenization into a new
ArgTokenizerunit and introduced focused unit tests for token shapes. This makes normalization rules (e.g.,--name=value, positional marking, and raw-token preservation) easier to maintain and test. Parsenow consumes token objects produced byTokenizeArgs, reducing complexity inArgParser.pasand improving separation of concerns.- Added
SplitCombinedShortsconfiguration toArgTokenizer.pasto control how short groups like-abcare handled (split into separate flags vs inline remainder). - Tests added for tokenizer edge-cases (cohorts, short-inline values, PowerShell '.'-append quirk).
Notes
- This release is primarily a refactor and test coverage improvement; behavior is compatible with previous releases except where noted.
Added / Changed
- Fast option lookup (
FLookup) to map-x/--nameswitches to internal option records. This improves parsing performance and centralizes option registration. - Positional arguments are strictly positional by default:
AddPositionalarguments are matched only by their position in the argument list and are no longer automatically registered as--nameswitches. This reduces ambiguity and better matches common CLI expectations. - Documentation updates across
README.md,docs/cheat-sheet.md, and the beginner's guide to explain the lookup behavior and the new positional semantics.
Fixed
- Fixed a small bug in
GetAllArrayand simplifiedAddPositionalposition index logic for maintainability.
Notes
- These changes are backward-compatible for most common use cases. Advanced callers that relied on positional arguments being accessible via
--nameshould update their call sites to add an explicit option if they still need the named form.
Added
- Positional arguments support via
AddPositionalwith ordered matching andNArgsfor fixed or variable consumption (NArgs = -1). ParseCommandLineKnown(out Leftovers)helper which supports the--separator and returns leftover tokens for forwarding to subcommands.- Allow multiple occurrences for options (accumulation) and
GetAll*accessors to retrieve all values in order (e.g.,GetAllString,GetAllArray). - Boolean negation using
--no-<option>to explicitly set boolean flags to false.
Changed / Fixed
ParseCommandLinenow detects a--separator and leftovers are available via theLeftoversproperty.SetErrorno longer frees resources automatically; this preserves the error message so callers can print it before callingShowUsage.- Parsing no longer auto-displays help; callers should check the
helpflag after parsing and callShowHelp/ShowUsageand exit. This avoids surprising resource finalization during parsing. - Fixed shell-related short-inline value handling (PowerShell dot-join cases where
-finput.txtcould be split into-finputand.txt). - Fixed memory leaks on error paths:
ShowUsageandShowHelpnow free internal resources after printing usage/help.
Initial public release (split out from TidyKit).
Added
- Examples and documentation
- Core features:
- Define short (
-f) and long (--file) options - Parse string, integer, float, boolean, and array value types
- Support for
--name=valueformat for all option types - Enhanced boolean options supporting
--verbose=true/falsesyntax - Automatic generation of usage and help text
- Callback support for immediate action on parsed arguments
- Methods to retrieve parsed values by option name
- Define short (
- Comprehensive unit tests
README.mdwith quick start guide and API reference- Example applications demonstrating usage
- MIT License
Changed
- Project renamed from ParseArgs to ArgParser; documentation updated accordingly.