google / textfsm

Python module for parsing semi-structured text into python tables.
Apache License 2.0
1.09k stars 168 forks source link

Request: add Boolean flag? #40

Closed joewesch closed 4 years ago

joewesch commented 5 years ago

Hello team,

I was hoping you could add a flag for values that would allow Boolean matches. Something like so:

Value Required INTERFACE (\S+)
Value INTERFACE_ZONE (.+?)
Value Boolean LINK_UP (up)
Value Boolean PROTOCOL_UP (up)

Start
  ^.*Interface ${INTERFACE} "${INTERFACE_ZONE}", is ${LINK_UP}.*protocol is ${PROTOCOL_UP}

(Just a quick example for reference. This wouldn't match on administratively down for example)

Instead of inserting the word "up" into the dictionary it would be true if the link is up and false if not. On each new Record it would reset back to false as the default value.

harro commented 5 years ago

This looks to be a post-processing vs inline processing issue.

Without such a flag, the value will either have the string "up", or not. Ands presently it would be necessary in post processing to assert that it is 'true' if the field is "up" and false otherwise.

With a Boolean flag feature the boolean assertion is done by Textfsm inline but this creates potential incompatibility between existing flags i.e. how would we interoperate the Boolean flag with any of the following flags: Filldown, Key, List and Fillup ?

buxtronix commented 4 years ago

Agreed, I don't think a boolean flag belongs in this kind of parser.

The python code can easily test for 'boolean-ness' by simply testing for a non-zero value in that column.