src/Nssm/PowerShellApplication.psm1

using namespace System.Management.Automation
using module ./Application.psm1

<#
.SYNOPSIS
    Represents a PowerShell application.
#>

class PowerShellApplication: Application {

    <#
    .SYNOPSIS
        The entry point of this application.
    #>

    hidden [string] $EntryPoint = ""

    <#
    .SYNOPSIS
        Creates a new application.
    .PARAMETER Path
        The path to the application root directory.
    #>

    PowerShellApplication([string] $Path): base($Path) {
        if ($file = Get-Item "$($this.Path)/*.psd1" -Exclude "PSModules.psd1" -ErrorAction Ignore) {
            $module = Import-PowerShellDataFile $file.FullName
            if (-not $this.Description) { $this.Description = $module.Description }
            if (-not $this.Name) { $this.Name = $file.BaseName }
            if ($module.RootModule) { $this.EntryPoint = Join-Path $this.Path $module.RootModule -Resolve -ErrorAction Ignore }
        }
    }

    <#
    .SYNOPSIS
        Gets the entry point of this application.
    .OUTPUTS
        The entry point of this application.
    #>

    [string] GetEntryPoint() {
        if ($this.EntryPoint) { return $this.EntryPoint }
        throw [EntryPointNotFoundException] "Unable to resolve the application entry point."
    }

    <#
    .SYNOPSIS
        Gets the name of the environment variable storing the application environment.
    .OUTPUTS
        The name of the environment variable storing the application environment.
    #>

    [string] GetEnvironmentVariable() {
        return "PODE_ENVIRONMENT"
    }

    <#
    .SYNOPSIS
        Gets the program used to run this application.
    .OUTPUTS
        The program used to run this application.
    #>

    [ApplicationInfo] GetProgram() {
        return Get-Command "pwsh"
    }
}