Reference

Command line based argument parse framework.

snip(flags, value, apply=None)

Get recursive representation of arguments based on the flags.

Parameters:
  • flags (dict) – Figure to use against value.
  • value (str) – Content to derive results.
  • apply (func) – Called on values, useful for sub-parsing.
>>> flags = {'-s': 'size', '-t': {'-b': 'base', '-t': 'toppings'}}
>>> value = 'big -t bbq \-t bacon -b tomato \-t mushroom'
>>> args = snip(flags, value) # multidict
draw(flags, empty=' ', clause='()', variable='[]', apply=None)

Draw description on how these flags expect arguments.

Parameters:
  • flags (dict) – Figure to derive result.
  • empty (str) – Used to join chunks.
  • clause (str) – Open and close of a sub-section.
  • variable (str) – Open and close of variable names.
  • apply (func) – Will be used on all variable names.
>>> flags = {'-s': 'size', '-t': {'-b': 'base', '-t': 'toppings'}}
>>> usage = draw(flags) # '-s [size] -t (-b [base] -t [toppings])'
trace(value, ignore='{}| ', clause='()', variable='[]')

Get flags from the string; used for drawing and snipping.

Parameters:
  • value (str) – The value to derive figure.
  • ignore (str) – Skip any character found here.

The rest are the same as in draw().

>>> usage = '-s [size] -t (-b {[base]} -t [toppings])'
>>> args = trace(usage) # {'-s': 'size', '-t': {'-b': 'base', '-t': 'toppings'}}