args_simple 1.3.0
args_simple: ^1.3.0 copied to clipboard
a simple argument parser and handler, integrated with JSON and dart:io.
1.3.0 #
ArgsSimple.parse: parsing behaviour changes:--now ends option parsing: every following element is an argument, even if it starts with-(['--', '-x']gives the argument-x). It used to be an option with an empty key that consumed the next element.--key=valueis now split on the first=: the optionkeywithvalue(which may be empty or contain=), without consuming the next element. It used to be the optionkeyvalueconsuming the next element as its value.--key valueis unchanged.--flag=trueis an option, not a flag (read it withoptionAsBool).- Keys keep Unicode letters and digits:
--Ünïcodeis nowünïcode(it used to bencode). Keys are still lower-cased and stripped of-,_,., spaces, punctuation and symbols, so--sys-config,--sys_configand--SysConfigremain the same key. ASCII keys are unchanged. -D/-Pare a property prefix only when followed bykey=value(orkey:value):-Port,-Debug,-Dverbose,-Pare now flags (port,debug,dverbose,p); they used to be the propertiesort,ebug,verboseand''with an empty value.-Dkey=value,-Pkey=valueand-Dkey:valueare unchanged.
ArgsSimple:toList: arguments starting with-(other than negative numbers) are emitted after--, soparse -> toList -> parseround-trips (an argument-xadded in code used to come back as a flag). An option with an empty key is emitted as--=value.toJson:flagsis now aList(it was aSet, sojsonEncode(args.toJson())failed when there were flags). Theoptionslists are copies.fromJson: aMapin thetoJsonformat (only the keysarguments,flags,options,properties, with the matching types) now loads all four sections, sotoJson -> fromJsonround-trips. Any otherMapis still read as options.normalizeKey: documented; uses a Unicode-aware character check.
TypeParser:parserFor: nullable built-in types (int?,String?,List?, ...) now get the parser of their non-nullable type (it returnednull), sooption<int?>('port')parses instead of throwing aTypeError.parseMap/parseMapEntry: a key or value that can't be parsed (parseMap<String, int>('a=x')) no longer throws aTypeError: the entry is skipped byparseMapandparseMapEntryreturnsdef(consistent with keys without a value in 1.2.1). A nullable type keeps the entry with anull. This also applies toMap,MapEntryandIterableinputs; a one-elementIterableis a key without a value.
- README: documented the parsing rules.
- Tests: regression tests for each change (failing on 1.2.1),
--/--key=value/Unicode/-P/-Dround-trips, a randomizedparse -> toList -> parseproperty test, andtoJson -> jsonEncode -> fromJsonround-trips. Tests: 127 -> 148. Line coverage: 100%.
1.2.1 #
ArgsSimple:- Fixed
argument/option/property(and the typed*AsInt,*AsDouble,*AsBool, ... accessors) throwing aTypeErrorwhen a value can't be parsed (e.g.--port abcwithoptionAsInt('port', 8080)): they now return the default (ornull).
- Fixed
TypeParser:- Fixed
parseMap/parseMapEntrythrowing aTypeErrorfor a key without a value (parseMap<String, String>('a;b=1')) when the value type is non-nullable: the entry is now skipped byparseMap({'b': '1'}) andparseMapEntryreturnsdef. A nullable/dynamic value type still keeps the key with anullvalue.
- Fixed
- Tests: added edge-case tests (empty input,
--,--key=value,=in values, repeated options/flags/properties,-P/-Dprefixes, negative numbers vs. flags, quoting, unicode),parse -> toList -> parseround-trips, and end-to-end tests running real processes (the example CLI, and a script comparing realargvparsing with in-process parsing). Tests: 69 -> 127. Line coverage: 99.3% -> 100%. - GitHub CI: the Codecov upload now uses the
CODECOV_TOKENsecret and fails CI on error.
1.2.0 #
-
ArgsSimple:toList: an option given more than once (stored as aList) is now emitted as one--key valuepair per value, sotoListround-trips throughparse(it used to emit--key [v1, v2]).
-
TypeParser:parseMapEntry/parseMap: fixed whitespace around the key/value delimiter leaking into the value ('a = 1'gave the value'= 1').- Use
Iterable.nonNullsinstead of the deprecatedwhereNotNullfrompackage:collection.
-
Removed unnecessary library names.
-
Removed dependency
collection(no longer used). -
Tests: added unit tests for
TypeParser,TypeParserIO, theArgsSimpleaccessors,fromJson, serialization and thedart:ioextension, plus integration tests running the example CLI. Line coverage: 31.5% -> 99.3%. -
GitHub CI:
actions/checkout@v7,codecov/codecov-action@v7; tests run on SDK 3.13.0 and stable. -
sdk: ^3.13.0
-
yaml: ^3.1.4
-
lints: ^6.1.0
-
test: ^1.33.0
-
dependency_validator: ^5.1.0
-
coverage: ^1.16.0
1.1.0 #
-
ArgsSimple:parse: allow multiple values for the same option.- Added
flagOr.
-
sdk: '>=3.0.0 <4.0.0'
-
collection: ^1.18.0
-
yaml: ^3.1.2
-
lints: ^2.1.1
-
test: ^1.24.9
-
dependency_validator: ^3.2.2
-
coverage: ^1.7.1
1.0.0 #
- Initial version.