forked from proxb/PoshRSJob
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request proxb#157 from copdips/dev
fix proxb#156 - Start-RSJob - be able to import private functions
- Loading branch information
Showing
7 changed files
with
150 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
Function GetFunctionByFile { | ||
[CmdletBinding()] | ||
param ( | ||
[string[]]$FilePath | ||
) | ||
|
||
$psMajorVersion = $PSVersionTable.PSVersion.Major | ||
$functionsInFile = @() | ||
ForEach ($thisFilePath in $FilePath) { | ||
Write-Verbose "Working on file : $thisFilePath" | ||
|
||
if (-not (Test-Path $thisFilePath)) { | ||
Write-Warning "Cannot find file : $thisFilePath" | ||
continue | ||
} | ||
|
||
try { | ||
Switch ($psMajorVersion) { | ||
'2' { | ||
$scriptBlockInFile = [ScriptBlock]::Create($(Get-Content $thisFilePath) -join [Environment]::NewLine) | ||
$functionsInFile += @(FindFunction -ScriptBlock $scriptBlockInFile) | ||
} | ||
Default { | ||
$AST = [System.Management.Automation.Language.Parser]::ParseFile($thisFilePath, [ref]$null, [ref]$null) | ||
$functionsInFile += $AST.FindAll( {$args[0] -is [System.Management.Automation.Language.FunctionDefinitionAst]} , $true) | ||
} | ||
} | ||
Write-Verbose "Functions found in file : $($functionsInFile.Name -join '; ')" | ||
} | ||
catch { | ||
Write-Warning "$thisFilePath : $($_.Exception.Message)" | ||
} | ||
} | ||
$functionsInFile | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Function GetFunctionDefinitionByFunction { | ||
[CmdletBinding()] | ||
param ( | ||
[parameter(ValueFromPipeline = $True)] | ||
$FunctionItem | ||
) | ||
|
||
if ($FunctionItem -is [PSCustomObject]) { | ||
# In case of Powershell v2 | ||
$function.Body.Trim().Trim("{}") | ||
} | ||
else { | ||
# In case of Powershell v3+ | ||
$function.Body.Extent.Text.Trim("{}") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
Function GetUsingVariables { | ||
Param ([scriptblock]$ScriptBlock) | ||
$ScriptBlock.ast.FindAll({$args[0] -is [System.Management.Automation.Language.UsingExpressionAst]},$True) | ||
$ScriptBlock.ast.FindAll( {$args[0] -is [System.Management.Automation.Language.UsingExpressionAst]}, $True) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters