Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Break out search argument to option parsing for v2 custom search commands #392

Merged
merged 1 commit into from
Dec 9, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion splunklib/searchcommands/search_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,19 @@ def _process_protocol_v1(self, argv, ifile, ofile):

debug('%s.process finished under protocol_version=1', class_name)

def _protocol_v2_option_parser(self, arg):
""" Determines if an argument is an Option/Value pair, or just a Positional Argument.
Method so different search commands can handle parsing of arguments differently.

:param arg: A single argument provided to the command from SPL
:type arg: str

:return: [OptionName, OptionValue] OR [PositionalArgument]
:rtype: List[str]

"""
return arg.split('=', 1)

def _process_protocol_v2(self, argv, ifile, ofile):
""" Processes records on the `input stream optionally writing records to the output stream.

Expand Down Expand Up @@ -704,7 +717,7 @@ def _process_protocol_v2(self, argv, ifile, ofile):

if args and type(args) == list:
for arg in args:
result = arg.split('=', 1)
result = self._protocol_v2_option_parser(arg)
if len(result) == 1:
self.fieldnames.append(str(result[0]))
else:
Expand Down