mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Improve zeek_script_args test case and documentation
This commit is contained in:
parent
39177ce8c9
commit
2d3b4dab74
7 changed files with 30 additions and 19 deletions
7
NEWS
7
NEWS
|
@ -34,6 +34,13 @@ New Functionality
|
|||
See https://docs.zeek.org/en/master/frameworks/logging.html#filter-log-records
|
||||
for more details.
|
||||
|
||||
- A new ``zeek_script_args`` variable contains a list of arguments passed
|
||||
to a script. E.g. either when explicitly executing Zeek like
|
||||
``zeek -- myscript.zeek -arg1 -arg2``, or when using Zeek as to interpret
|
||||
executable scripts that contain a hashbang line at the top like::
|
||||
|
||||
#!/usr/local/zeek/bin/zeek --
|
||||
|
||||
Changed Functionality
|
||||
---------------------
|
||||
|
||||
|
|
|
@ -455,15 +455,15 @@ type connection: record {
|
|||
};
|
||||
|
||||
## Arguments given to Zeek from the command line. In order to use this, Zeek
|
||||
## must use the "--" command line argument, then give the script name immediately
|
||||
## after the double hyphens and the provide the arguments after that. For example:
|
||||
##
|
||||
## must use a ``--`` command line argument immediately followed by a script
|
||||
## file and additional arguments after that. For example::
|
||||
##
|
||||
## zeek --bare-mode -- myscript.zeek -a -b -c
|
||||
##
|
||||
##
|
||||
## To use Zeek as an executable interpreter, include a line at the top of a script
|
||||
## like the following and make the script executable:
|
||||
##
|
||||
## #!/usr/local/zeek/bin/zeek --
|
||||
## like the following and make the script executable::
|
||||
##
|
||||
## #!/usr/local/zeek/bin/zeek --
|
||||
const zeek_script_args: vector of string = vector();
|
||||
|
||||
## Default amount of time a file can be inactive before the file analysis
|
||||
|
|
|
@ -30,8 +30,6 @@ zeek::VectorType* index_vec;
|
|||
zeek::VectorType* mime_matches;
|
||||
zeek::RecordType* mime_match;
|
||||
|
||||
zeek::VectorVal* zeek_script_args;
|
||||
|
||||
zeek::RecordType* socks_address;
|
||||
|
||||
zeek::TableVal* tcp_reassembler_ports_orig;
|
||||
|
|
|
@ -663,7 +663,7 @@ SetupResult setup(int argc, char** argv, Options* zopts)
|
|||
// Assign the script_args for command line processing in Zeek scripts.
|
||||
if ( ! options.script_args.empty() )
|
||||
{
|
||||
auto script_args_val = zeek::id::find_val("zeek_script_args")->AsVectorVal();
|
||||
auto script_args_val = id::find_val<VectorVal>("zeek_script_args");
|
||||
for ( const string& script_arg : options.script_args )
|
||||
{
|
||||
script_args_val->Assign(script_args_val->Size(), make_intrusive<StringVal>(script_arg));
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
[-a, -b, -c]
|
||||
[-d, -e, -f]
|
14
testing/btest/core/script-args.zeek
Normal file
14
testing/btest/core/script-args.zeek
Normal file
|
@ -0,0 +1,14 @@
|
|||
# @TEST-EXEC: printf '#!' > test.zeek
|
||||
# @TEST-EXEC: printf "$BUILD/src/zeek -b --\n" >> test.zeek
|
||||
# @TEST-EXEC: cat %INPUT >> test.zeek
|
||||
# @TEST-EXEC: chmod u+x test.zeek
|
||||
|
||||
# @TEST-EXEC: zeek -b -- %INPUT -a -b -c >out
|
||||
# @TEST-EXEC: $(dirname %INPUT)/test.zeek -d -e -f >>out
|
||||
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
event zeek_init()
|
||||
{
|
||||
print zeek_script_args;
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
# @TEST-EXEC: zeek -b -- %INPUT -a -b -c
|
||||
|
||||
# @TEST-EXEC: btest-diff .stdout
|
||||
|
||||
event zeek_init()
|
||||
{
|
||||
print zeek_script_args;
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue