Example 1
The following example shows how you can send output directly to the console:
<# setoutput console #>
This message appears in the console window (whether or not you use verbose mode).
<#endsetoutput #>
Example 2
The following example shows how you can send a single argument to the console:
<# puts (msg) #>
!==================================================================
!==================================================================
! output "msg" to console
!==================================================================
!==================================================================
<# setoutput console #>
<# msg; "\n"#>
<#endsetoutput #>
<# endtmpl #>
!==================================================================
!==================================================================
<# tmpl.puts(“ Hello World” )
Invoking Other Macros
Macros can invoke other macros within the same macro file; a macro can also invoke a
macro from another macro file if the invocation takes place in literal text, that is, not
within a control expression. A macro can invoke itself directly or indirectly (an invoked
macro can invoke the macro that invoked it); the number of nested invocations is limited
to 10 to prevent infinite recursion.
Within each macro, you can specify parameters that
must
be passed to the macro when
it is invoked by another. You must specify named variables enclosed in parentheses after
the macro name in the first line of the macro, as shown in this example:
<#
macroName
(count, total) #>
Additional parameters can be passed as well. Parameters can be local variables,
environmental variables, literals, or operations. The invoking macro passes local variables
by reference to the invoked macro. Passing parameters has no effect on the invoking
macro unless the parameter is a local variable that is changed by the invoked macro.
When the invoked macro completes execution, the local variable assumes the new value
for the invoking macro.
The invoked macro can use the
param[
n
]
expression to access parameters passed to
it, where
n
is the number of the parameter passed. This is useful if optional parameters
can be passed to a macro or if the same iterative algorithm needs to process the
parameters.
Use the expression
param[0]
to return the total number of parameters passed to the
macro. Use the
return
keyword to halt execution of the invoked macro and resume
execution of the invoking macro. Use the
exit
keyword to halt execution of all macros.
Example 1
The following sample macro demonstrates macro invocation:
<# invoking_examples #>
<# //---------------------------------------- #>
<# name := env.getline("What is your first name? ") #>
475
Copyright © 2010, Juniper Networks, Inc.
Chapter 8: Writing CLI Macros
Summary of Contents for JUNOSE 11.3
Page 6: ...Copyright 2010 Juniper Networks Inc vi...
Page 8: ...Copyright 2010 Juniper Networks Inc viii JunosE 11 3 x System Basics Configuration Guide...
Page 24: ...Copyright 2010 Juniper Networks Inc xxiv JunosE 11 3 x System Basics Configuration Guide...
Page 32: ...Copyright 2010 Juniper Networks Inc 2 JunosE 11 3 x System Basics Configuration Guide...
Page 146: ...Copyright 2010 Juniper Networks Inc 116 JunosE 11 3 x System Basics Configuration Guide...
Page 166: ...Copyright 2010 Juniper Networks Inc 136 JunosE 11 3 x System Basics Configuration Guide...
Page 432: ...Copyright 2010 Juniper Networks Inc 402 JunosE 11 3 x System Basics Configuration Guide...
Page 488: ...Copyright 2010 Juniper Networks Inc 458 JunosE 11 3 x System Basics Configuration Guide...
Page 524: ...Copyright 2010 Juniper Networks Inc 494 JunosE 11 3 x System Basics Configuration Guide...
Page 554: ...Copyright 2010 Juniper Networks Inc 524 JunosE 11 3 x System Basics Configuration Guide...
Page 566: ...Copyright 2010 Juniper Networks Inc 536 JunosE 11 3 x System Basics Configuration Guide...
Page 588: ...Copyright 2010 Juniper Networks Inc 558 JunosE 11 3 x System Basics Configuration Guide...
Page 613: ...PART 3 Index Index on page 585 583 Copyright 2010 Juniper Networks Inc...
Page 614: ...Copyright 2010 Juniper Networks Inc 584 JunosE 11 3 x System Basics Configuration Guide...
Page 632: ...Copyright 2010 Juniper Networks Inc 602 JunosE 11 3 x System Basics Configuration Guide...