generated from PSModule/Template-PSModule
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature]: Introduce new AST command functions and update examples fo…
…r consistency
- Loading branch information
1 parent
889f0fb
commit 7fe3893
Showing
10 changed files
with
81 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
# Gets the AST of a script. Can be any type of PowerShell script file. | ||
Get-ScriptAST -Path $path | ||
Get-ASTScript -Path $path | ||
|
||
# Gets the AST of a function(s) in a script. Can be any type of PowerShell script file. | ||
Get-FunctionAST -Path $path | ||
Get-ASTFunction -Path $path | ||
|
||
# Gets the type of all functions in a script file. Function or filter. | ||
Get-FunctionType -Path $path | ||
Get-ASTFunctionType -Path $path | ||
|
||
# Gets the name of all functions in a script file. | ||
Get-FunctionName -Path $path | ||
Get-ASTFunctionName -Path $path | ||
|
||
# Gets the alias of a function in a script, that uses Alias attribute. | ||
Get-FunctionAlias -Path $path | ||
Get-ASTFunctionAlias -Path $path | ||
|
||
'Get-ChildItem -Path . # This is a comment' | Get-LineComment | ||
'Get-ChildItem -Path . # This is a comment' | Get-ASTLineComment |
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,25 @@ | ||
function Get-ASTCommand { | ||
[CmdletBinding()] | ||
param ( | ||
# The name of the command to search for. Defaults to all commands ('*'). | ||
[Parameter()] | ||
[string] $Name = '*', | ||
|
||
# The path to the PowerShell script file to be parsed. | ||
[Parameter(Mandatory)] | ||
[ValidateScript({ Test-Path -Path $_ -PathType Leaf })] | ||
[string] $Path | ||
) | ||
|
||
begin {} | ||
|
||
process { | ||
# Parse the script file into an AST | ||
$ast = Get-ASTScript -Path $Path | ||
|
||
# Extract function definitions | ||
$ast.FindAll({ $args[0] -is [System.Management.Automation.Language.CommandAst] }, $true) | Where-Object { $_.Name -like $Name } | ||
} | ||
|
||
end {} | ||
} |
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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