codingdojo/args
2023-09-28 23:12:48 +02:00
..
tests Fixed typos and useless code. 2023-09-28 23:12:48 +02:00
args.py Fixed typos and useless code. 2023-09-28 23:12:48 +02:00
README.md Fixed typos and useless code. 2023-09-28 23:12:48 +02:00

A Simple and stupid Args Parser.

The subject was found here: https://codingdojo.org/kata/Args/

This implementation requires no dependencies (but probably comes with some bugs).

Defining the pattern

An arguments pattern is defined by a comma-separated expressions with the following format:

FLAG:NAME:TYPE[*]
  • FLAG must be one character only, and is the token that should be encountered on the line to parse.
  • NAME is the argument name, and will be the name of the available matching property once the command line was parsed.
  • TYPE can be b for boolean, d for an integer (think C), s for a string. If the format is followed by a star, then the argument should be a comma-separated list of values with the given type.

The tests are full of samples.

Known limitations

  • Pattern parsing is fragile, as it misses many tests on the input.
  • Boolean arrays were not considered.

Tests

Unit tests for pytest and siblings are available in the tests directory. Because of laziness and lack of time, they only examine the parse function as a black box.