]> git.proxmox.com Git - mirror_frr.git/commit
python: make DEFPY provide the text token of fixed parameters
authorRenato Westphal <renato@opensourcerouting.org>
Sat, 19 Jan 2019 19:24:09 +0000 (17:24 -0200)
committerRenato Westphal <renato@opensourcerouting.org>
Mon, 21 Jan 2019 13:11:00 +0000 (11:11 -0200)
commit5254bb1550fd29484310a2e1cb94030a50dd815b
tree90147554ebd6e669b78bb1f5723972a83680412a
parent70fc94ca1d6063b64449b0971678521c021ac916
python: make DEFPY provide the text token of fixed parameters

In the CLI code, each cmd_token has both a "text" field, containing
the full token text (e.g. "unicast"), and an "arg" field,
containing the original text entered by the user (which might be
an abbreviation, like "uni" instead of "unicast").

To avoid the need to handle abbreviations, the recommended pattern
for DEFUN commands is to use the "text" value of fixed parameters
and the "arg" value of everything else.

Using DEFPY, however, the CLI parameters are automagically turned
into C variables which are initialized under the hood (so that
they're conveniently ready for use). The problem is that this
initialization was always using the "arg" value of the parameters,
which was leading to problems like these:

  debian# show ipv6 route isi
  Unknown route type
  debian#
  debian# conf t
  debian(config)# router isis 1
  debian(config-router)# redistribute ipv4 st level-1
  % Configuration failed.

  Invalid value "st" in "protocol" element.
  YANG path: /frr-isisd:isis/instance[area-tag='1']/redistribute/ipv4[protocol='st']/protocol

To fix these problems (and probably others too), make DEFPY commands
auto-detect the type of the input parameters and use either the
"arg" or "text" value from the cmd_tokens accordingly.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
python/clidef.py