Skip to content

v1.3.0

Latest

Choose a tag to compare

@gmpassos gmpassos released this 04 Nov 07:24
e57aa47
  • 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=value is now split on the first =: the option key with value (which may be empty or contain =), without consuming the next element. It used to be the option keyvalue consuming the next element as its value. --key value is unchanged. --flag=true is an option, not a flag (read it with optionAsBool).
    • Keys keep Unicode letters and digits: --Ünïcode is now ünïcode (it used to be ncode). Keys are still lower-cased and stripped of -, _, ., spaces, punctuation and symbols, so --sys-config, --sys_config and --SysConfig remain the same key. ASCII keys are unchanged.
    • -D/-P are a property prefix only when followed by key=value (or key:value): -Port, -Debug, -Dverbose, -P are now flags (port, debug, dverbose, p); they used to be the properties ort, ebug, verbose and '' with an empty value. -Dkey=value, -Pkey=value and -Dkey:value are unchanged.
  • ArgsSimple:
    • toList: arguments starting with - (other than negative numbers) are emitted after --, so parse -> toList -> parse round-trips (an argument -x added in code used to come back as a flag). An option with an empty key is emitted as --=value.
    • toJson: flags is now a List (it was a Set, so jsonEncode(args.toJson()) failed when there were flags). The options lists are copies.
    • fromJson: a Map in the toJson format (only the keys arguments, flags, options, properties, with the matching types) now loads all four sections, so toJson -> fromJson round-trips. Any other Map is 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 returned null), so option<int?>('port') parses instead of throwing a TypeError.
    • parseMap/parseMapEntry: a key or value that can't be parsed (parseMap<String, int>('a=x')) no longer throws a TypeError: the entry is skipped by parseMap and parseMapEntry returns def (consistent with keys without a value in 1.2.1). A nullable type keeps the entry with a null. This also applies to Map, MapEntry and Iterable inputs; a one-element Iterable is 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/-D round-trips, a randomized parse -> toList -> parse property test, and toJson -> jsonEncode -> fromJson round-trips. Tests: 127 -> 148. Line coverage: 100%.