1 # pseudo #!/PowerShell :)
3 # test file for the CTags/Geany PowerShell tag parser
4 # based on real world code but simplified for automated tests
7 multiline comment including a
function and variable
, both should be ignored
:
9 $IgnoreThisVaribale = "Stop"
11 function IgnoreThisFunction
($arg1) {
16 # immediately stop the script if an errors occurs
17 $ErrorActionPreference = "Stop"
19 # a global scoped variable
20 $Global:Settings
= $null
22 # a local scoped variable
23 $Local:ALocalVar
= $null
26 $BasePath = split-path
-parent
$Global:MyInvocation
.InvocationName
29 FUNCTION Read-Configuration-File
() {
30 $Hostname = [System
.Environment
]::MachineName
31 $ConfigurationFileName = $BasePath + "\script-${Hostname}.conf"
32 LogMessage
"Read configuration '${ConfigurationFileName}'"
34 $ConfigFileContent = Get-Content -raw
$ConfigurationFileName
35 $Global:Settings
= Convertfrom-Stringdata
$ConfigFileContent
38 Function LogMessageOK
()
40 $x = [Console
]::WindowWidth
- 6
41 $y = [Console
]::CursorTop
43 [Console
]::setcursorposition
($x, $y)
44 } Catch
[system
.exception
] {
45 # intentionally left empty for redirect of outputs to file
48 Write-Host -foregroundcolor
"green" "[ok]"
51 function LogMessage
() {
53 [Parameter
(Mandatory
=$false)][switch] $NoNewLine,
54 [Parameter
(Mandatory
=$true)][string
] $Message
56 $Date = Get-Date -UFormat
"%Y-%m-%d %T: "
57 Write-Host -foregroundcolor
"yellow" -NoNewLine
$Date
60 Write-Host -foregroundcolor
"green" -NoNewLine
$Message
62 Write-Host -foregroundcolor
"green" $Message
66 function global
:A-Global-Scope-Function
() {
70 filter Script
:MyFilter
{
74 Filter Private
:MyPrivateFilter
{
78 function LoadTemplate
($template) {
79 # woah, this is real magic,
80 # see http://stackoverflow.com/questions/10754582/string-interpolation-of-hashtable-values-in-powershell
82 # Set all unbound variables (@args) in the local context
85 ($key, $val, $args) = $args
86 Set-Variable -Name
$key.SubString
(1, $key.Length-2
) -Value
$val
88 $ExecutionContext.InvokeCommand
.ExpandString
($template)
91 function TopLevelFunction
() {
92 function SecondLevelNestedFunction
() {
93 function ThirdLevelNestedFunction
() {
97 ThirdLevelNestedFunction
100 SecondLevelNestedFunction
104 Read-Configuration-File
105 LogMessage $("Working on Environment '{0}'" -f $Settings["EnvironmentName"])
107 LogMessage
"do something ..."