Skip to content

Commit

Permalink
Implement some features from backlog
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-peterson committed Apr 25, 2023
1 parent 16af9ff commit a4f9d29
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 123 deletions.
113 changes: 9 additions & 104 deletions src/Format-Markdown/Format-Markdown.psd1
Original file line number Diff line number Diff line change
@@ -1,116 +1,21 @@
@{

# Script module or binary module file associated with this manifest.
# RootModule = ''

# Version number of this module.
ModuleVersion = '1.0.1'

# Supported PSEditions
# CompatiblePSEditions = @()

# ID used to uniquely identify this module
ModuleVersion = '1.1.0'
GUID = '4ccaec92-6067-444f-8987-0d6dbcc55d8b'

# Author of this module
Author = 'Chris Peterson'

# Company or vendor of this module
CompanyName = 'Chris Peterson'

# Copyright statement for this module
Copyright = '(c) 2021 - 2022'

# Description of the functionality provided by this module
Copyright = '(c) 2021 - 2023'
Description = 'Format PowerShell object to Markdown'

# Minimum version of the Windows PowerShell engine required by this module
PowerShellVersion = '5.0'

# Name of the Windows PowerShell host required by this module
# PowerShellHostName = ''

# Minimum version of the Windows PowerShell host required by this module
# PowerShellHostVersion = ''

# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
# DotNetFrameworkVersion = ''

# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
# CLRVersion = '4.0'

# Processor architecture (None, X86, Amd64) required by this module
# ProcessorArchitecture = ''

# Modules that must be imported into the global environment prior to importing this module
# RequiredModules = @()

# Assemblies that must be loaded prior to importing this module
# RequiredAssemblies = @()

# Script files (.ps1) that are run in the caller's environment prior to importing this module.
# ScriptsToProcess = @()

# Type files (.ps1xml) to be loaded when importing this module
# TypesToProcess = @()

# Format files (.ps1xml) to be loaded when importing this module
# FormatsToProcess = @()

# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
NestedModules = @('Format-Markdown.psm1')

# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = 'Format-Markdown'

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = ''

# Variables to export from this module
VariablesToExport = ''

# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
CmdletsToExport = @()
VariablesToExport = @()
AliasesToExport = 'fmd'

# DSC resources to export from this module
# DscResourcesToExport = @()

# List of all modules packaged with this module
# ModuleList = @()

# List of all files packaged with this module
# FileList = @()

# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
PrivateData = @{

PSData = @{

# Tags applied to this module. These help with module discovery in online galleries.
# Tags = @()

# A URL to the license for this module.
LicenseUri = 'https://github.com/chris-peterson/pwsh-fmd/blob/master/LICENSE'

# A URL to the main website for this project.
ProjectUri = 'https://github.com/chris-peterson/pwsh-fmd'

# A URL to an icon representing this module.
# IconUri = ''

# ReleaseNotes of this module
# ReleaseNotes = ''

} # End of PSData hashtable

} # End of PrivateData hashtable

# HelpInfo URI of this module
# HelpInfoURI = ''

# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
# DefaultCommandPrefix = ''

LicenseUri = 'https://github.com/chris-peterson/pwsh-fmd/blob/master/LICENSE'
ProjectUri = 'https://github.com/chris-peterson/pwsh-fmd'
ReleaseNotes = ''
}
}


}
55 changes: 36 additions & 19 deletions src/Format-Markdown/Format-Markdown.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ function Format-Markdown{
param (
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[PSObject[]]
$InputObject
$InputObject,

[switch]
[Parameter()]
$AsJsonTable
)

Begin {
Expand All @@ -28,28 +32,41 @@ function Format-Markdown{
}

End {
foreach ($Key in $($Columns.Keys)) {
$Columns[$Key] = [Math]::Max($Columns[$Key], $Key.Length)
}
$Output = ''
if ($AsJsonTable) {
$Output += "``````json:table`n"
$Json = @{
fields = $Columns.Keys | ForEach-Object { @{ key = $_; label = $_; sortable = 'true'}}
items = $Items | ForEach-Object { $_.PSObject.Properties.GetEnumerator() | ForEach-Object { @{ $_.Name = $_.Value } } }
filter = 'true'
}
$Output += "$($Json | ConvertTo-Json -Compress)`n"
$Output += "```````n"
} else {
foreach ($Key in $($Columns.Keys)) {
$Columns[$Key] = [Math]::Max($Columns[$Key], $Key.Length)
}

$HeaderRow = @()
foreach ($Key in $Columns.Keys) {
$HeaderRow += ('{0,-' + $Columns[$Key] + '}') -f $Key
}
Write-Output "$($HeaderRow -join ' | ')`n"
$HeaderRow = @()
foreach ($Key in $Columns.Keys) {
$HeaderRow += ('{0,-' + $Columns[$Key] + '}') -f $Key
}
$Output += "$($HeaderRow -join ' | ')`n"

$SeparatorRow = @()
foreach ($Key in $Columns.Keys) {
$SeparatorRow += '-' * $Columns[$Key]
}
Write-Output "$($SeparatorRow -join ' | ')`n"
$SeparatorRow = @()
foreach ($Key in $Columns.Keys) {
$SeparatorRow += '-' * $Columns[$Key]
}
$Output += "$($SeparatorRow -join ' | ')`n"

foreach ($Item in $Items) {
$DataRow = @()
foreach($key in $Columns.Keys) {
$DataRow += ('{0,-' + $Columns[$key] + '}') -f $Item.($key)
foreach ($Item in $Items) {
$DataRow = @()
foreach($key in $Columns.Keys) {
$DataRow += ('{0,-' + $Columns[$key] + '}') -f $Item.($key)
}
$Output += "$($DataRow -join ' | ')`n"
}
Write-Output "$($DataRow -join ' | ')`n"
}
Write-Output $Output
}
}

0 comments on commit a4f9d29

Please sign in to comment.