jhwohlgemuth / pwsh-prelude

PowerShell “standard” library for supercharging your productivity. Provides a powerful cross-platform scripting environment enabling efficient analysis and sustainable science in myriad contexts.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cool suggestions

couleurm opened this issue · comments

Hey, I'm looking for cool stuff to add/make to my ""module"" and I really like Prelude, might snag some of your useful functions :-)

Some ideas popped in my head that I'd see you me and you using/making, consider that a suggestion and/or a PR if I end up making it some of that stuff myself

Function dependency parser using AST

Extract a minimal amount of functions out of a module without breaking stuff to get a single function working (could support multiple in the future 🤷‍♂️)

You give it a function name you've got declared/imported, and files/directories/modules to search in, I've messed with AST to make it work like this:

$Block = {
    Invoke-Pack @Thing
    Invoke-Unpack @Stuff
}
$TL_FUNCTIONS = ('Invoke-Pack', 'Invoke-Unpack')

$AST = [System.Management.Automation.Language.Parser]::ParseInput($Block, [ref]$null, [ref]$null)
                
$DepMatches = $AST.FindAll({
        param ($node)
        $node.GetType().Name -eq 'CommandAst'
    }, $true) | #It gets all cmdlets from the Abstract Syntax Tree
ForEach-Object {$_.CommandElements[0].Value} | # Returns their name
    Where-Object { # Filters out only TweakList functions
        $_ -In $TL_FUNCTIONS

    } | Select-Object -Unique

return $DepMatches

I've made something like this that may work better, see Get-FunctionContent, you probably will want to use -ReturnNames to make it more convenient to use

Markdown tree-style display for your module

^ Each folders add a `t, each file is parsed to find the functions it contains with AST (or check which new functions exist compared to before dot sourcing it), then use Get-Help to get it's <# .SYNOPSIS #> to add as a description after the * $_.Name -

Example

  • /Modules/
    • /Public/
      • File.ps1
        • Func Invoke-Pack - Function that will serialize one or more files into a single XML file. Use Invoke-Unpack to restore files.
        • Func Invoke-Unpack - cba getting it's synopsis, you get the point that'd be sick to automatically generate

Example usecase: Generate that with CI in the part of a README, hyperlink everything with a permalink, and hyperlink Func to link to the param( line

Replace wathever is between <--START_ID!--> and <--END_ID!--> flags in a README file

If you're using the function I explained last in your README with CI, you'd probably want to replace it in your README at a specific place, you could add a line that is a markdown comment that contains START_ and your $BLOCKNAME so you can have multiple replace blocks, so at every commit it's wiped fresh at the place you'd expect it to

Update: got ambitious about the two last points and made couleur-tweak-tips/Show-ModuleTree