2021-09-20 11:19:34 +00:00
|
|
|
#!rsc by RouterOS
|
2021-11-15 19:22:56 +00:00
|
|
|
# RouterOS script: mod/inspectvar
|
2023-01-02 22:33:49 +00:00
|
|
|
# Copyright (c) 2020-2023 Christian Hesse <mail@eworm.de>
|
2021-09-20 11:19:34 +00:00
|
|
|
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
|
|
|
|
|
|
|
|
:global InspectVar;
|
2021-12-09 15:13:00 +00:00
|
|
|
:global InspectVarReturn;
|
2021-09-20 11:19:34 +00:00
|
|
|
|
2021-12-09 15:13:00 +00:00
|
|
|
# inspect variable and print on terminal
|
2021-09-20 11:19:34 +00:00
|
|
|
:set InspectVar do={
|
2021-12-09 15:13:00 +00:00
|
|
|
:global InspectVarReturn;
|
2022-07-05 10:40:07 +00:00
|
|
|
:global PrettyPrint;
|
2021-12-09 15:13:00 +00:00
|
|
|
|
2022-07-05 10:40:07 +00:00
|
|
|
$PrettyPrint [ $InspectVarReturn $1 ];
|
2021-12-09 15:13:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# inspect variable and return formatted string
|
|
|
|
:set InspectVarReturn do={
|
2021-09-20 11:19:34 +00:00
|
|
|
:local Input $1;
|
|
|
|
:local Level (0 + [ :tonum $2 ]);
|
|
|
|
|
2021-12-09 19:50:51 +00:00
|
|
|
:global IfThenElse;
|
2021-12-09 15:13:00 +00:00
|
|
|
:global InspectVarReturn;
|
2021-09-20 11:19:34 +00:00
|
|
|
|
2021-12-09 15:13:00 +00:00
|
|
|
:local IndentReturn do={
|
2021-09-20 11:19:34 +00:00
|
|
|
:local Prefix [ :tostr $1 ];
|
|
|
|
:local Value [ :tostr $2 ];
|
|
|
|
:local Level [ :tonum $3 ];
|
|
|
|
|
|
|
|
:local Indent "";
|
|
|
|
:for I from=1 to=$Level step=1 do={
|
|
|
|
:set Indent ($Indent . " ");
|
|
|
|
}
|
2021-12-09 15:13:00 +00:00
|
|
|
:return ($Indent . "-" . $Prefix . "-> " . $Value);
|
2021-09-20 11:19:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
:local TypeOf [ :typeof $Input ];
|
2021-12-09 15:13:00 +00:00
|
|
|
:local Return [ $IndentReturn "type" $TypeOf $Level ];
|
2021-09-20 11:19:34 +00:00
|
|
|
|
|
|
|
:if ($TypeOf = "array") do={
|
|
|
|
:foreach Key,Value in=$Input do={
|
2021-12-09 15:13:00 +00:00
|
|
|
:set $Return ($Return . "\n" . \
|
|
|
|
[ $IndentReturn "key" $Key ($Level + 1) ] . "\n" . \
|
|
|
|
[ $InspectVarReturn $Value ($Level + 2) ]);
|
2021-09-20 11:19:34 +00:00
|
|
|
}
|
|
|
|
} else={
|
|
|
|
:if ($TypeOf != "nothing") do={
|
2021-12-09 15:13:00 +00:00
|
|
|
:set $Return ($Return . "\n" . \
|
2021-12-09 19:50:51 +00:00
|
|
|
[ $IndentReturn "value" [ $IfThenElse ([ :len $Input ] > 80) \
|
|
|
|
([ :pick $Input 0 77 ] . "...") $Input ] $Level ]);
|
2021-09-20 11:19:34 +00:00
|
|
|
}
|
|
|
|
}
|
2021-12-09 15:13:00 +00:00
|
|
|
:return $Return;
|
2021-09-20 11:19:34 +00:00
|
|
|
}
|