Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 27 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
# Ast

A PowerShell module for using the Abstract Syntax Tree (AST) on any PowerShell code.

## Prerequisites

This uses the following external resources:
- The [PSModule framework](https://github.com/PSModule) for building, testing and publishing the module.
Ast is a PowerShell module for using the PowerShell abstract syntax tree (AST) to analyze PowerShell code. It provides
commands to extract functions, commands, aliases, comments, and script structure from a file, a string of script content,
or an existing AST object.

## Installation

To install the module from the PowerShell Gallery, you can use the following command:
Install the module from the PowerShell Gallery:

```powershell
Install-PSResource -Name Ast
Expand All @@ -18,39 +15,40 @@ Import-Module -Name Ast

## Usage

Here is a list of example that are typical use cases for the module.

### Example 1: Get the function name from a script
The commands accept a file path (`-Path`) or inline script content (`-Script`), and default to matching everything so
you can narrow the results with `-Name`.

This example shows how to get the function name from a script.
### Example: List the functions defined in a script

```powershell
Get-AstFunctionName -Path 'Test-Me.ps1'
Test-Me
Get-AstFunction -Path ./MyScript.ps1
Get-AstFunctionName -Path ./MyScript.ps1
Comment thread
MariusStorhaug marked this conversation as resolved.
```

### Find more examples
### Example: Find the commands invoked by a script

To find more examples of how to use the module, please refer to the [examples](examples) folder.

Alternatively, you can use the Get-Command -Module 'This module' to find more commands that are available in the module.
To find examples of each of the commands you can use Get-Help -Examples 'CommandName'.
```powershell
Get-AstCommand -Path ./MyScript.ps1
Get-AstCommand -Script "Get-Process; Write-Host 'Hello'"
```

## Contributing
### Example: Inspect a single function by name

Coder or not, you can contribute to the project! We welcome all contributions.
```powershell
Get-AstFunction -Path ./MyScript.ps1 -Name 'Test-Me'
```

### For Users
## Documentation

If you don't code, you still sit on valuable information that can make this project even better. If you experience that the
product does unexpected things, throw errors or is missing functionality, you can help by submitting bugs and feature requests.
Please see the issues tab on this project and submit a new issue that matches your needs.
Documentation is published at [psmodule.io/Ast](https://psmodule.io/Ast/).

### For Developers
Use PowerShell help and command discovery for module details:

If you do code, we'd love to have your contributions. Please read the [Contribution guidelines](CONTRIBUTING.md) for more information.
You can either help by picking up an existing issue or submit a new one if you have an idea for a new feature or improvement.
```powershell
Get-Command -Module Ast
Get-Help -Name Get-AstFunction -Examples
```

## Tools
## Related tools

- [lzybkr/ShowPSAst](https://github.com/lzybkr/ShowPSAst)
- [lzybkr/ShowPSAst](https://github.com/lzybkr/ShowPSAst) — an interactive viewer for exploring the PowerShell AST.
Loading