rdmarsh / elm

A cli interface for extracting LogicMonitor data via the api
GNU General Public License v3.0
2 stars 1 forks source link

Text string filter (--filter) can't filter using strings that contain a comma #31

Closed rdmarsh closed 1 year ago

rdmarsh commented 1 year ago

Describe the bug It is not possible to filter (-F/--filter) using a comma in the filter string.

To Reproduce Steps to reproduce the behavior:

  1. Run any filer using -F/--filter that contains a comma.

Expected behavior Be able to filter on fields that contain a comma.

Screenshots

$ elm DeviceList -F displayName~test,
Usage: elm DeviceList [OPTIONS]

Error: Invalid value for '--filter' / '-F': format must be 'FIELD[>:,<:,>,<,!:,:,~,!~]VALUE'

$ elm DeviceList -F displayName~test\,
Usage: elm DeviceList [OPTIONS]

Error: Invalid value for '--filter' / '-F': format must be 'FIELD[>:,<:,>,<,!:,:,~,!~]VALUE'

$ elm DeviceList -F "displayName~test\,"
Usage: elm DeviceList [OPTIONS]

Error: Invalid value for '--filter' / '-F': format must be 'FIELD[>:,<:,>,<,!:,:,~,!~]VALUE'

$ elm DeviceList -F "displayName~test,"
Usage: elm DeviceList [OPTIONS]

Error: Invalid value for '--filter' / '-F': format must be 'FIELD[>:,<:,>,<,!:,:,~,!~]VALUE'

$ elm DeviceList -F 'displayName~test,'
Usage: elm DeviceList [OPTIONS]

Error: Invalid value for '--filter' / '-F': format must be 'FIELD[>:,<:,>,<,!:,:,~,!~]VALUE'

$ elm DeviceList -F 'displayName~test,,'
Usage: elm DeviceList [OPTIONS]

Error: Invalid value for '--filter' / '-F': format must be 'FIELD[>:,<:,>,<,!:,:,~,!~]VALUE'

$ elm DeviceList -F 'displayName~test\\,'
Usage: elm DeviceList [OPTIONS]

Error: Invalid value for '--filter' / '-F': format must be 'FIELD[>:,<:,>,<,!:,:,~,!~]VALUE'

$ elm DeviceList -F 'displayName~test\\\,'
Usage: elm DeviceList [OPTIONS]

Error: Invalid value for '--filter' / '-F': format must be 'FIELD[>:,<:,>,<,!:,:,~,!~]VALUE'

Desktop (please complete the following information):

rdmarsh commented 1 year ago

Regex will be something like:

for filter in re.split(r'(?<!,),', filters):

rdmarsh commented 1 year ago
+        #split filters by commas except if they're proceeded by a backslash
+        for filter in re.split(r'[^\\],', filters):
+            #now remove the backslash we used to protect the comma from split above
+            filter = filter.replace('\\,',',')
rdmarsh commented 1 year ago

Closing, resolved with commit b34d743