Skip to content

Implement Toml module with full TOML 1.0.0 support#15

Open
Marius Storhaug (MariusStorhaug) wants to merge 1 commit into
mainfrom
build-toml-module
Open

Implement Toml module with full TOML 1.0.0 support#15
Marius Storhaug (MariusStorhaug) wants to merge 1 commit into
mainfrom
build-toml-module

Conversation

@MariusStorhaug

Copy link
Copy Markdown
Member

Summary

Implements a production-quality PowerShell module for reading and writing TOML data, following PSModule and MSXOrg standards.

Public API

Command Description
ConvertFrom-Toml Parse TOML text → TomlDocument
ConvertTo-Toml Serialize object/TomlDocument → TOML text
Import-Toml Read TOML file → TomlDocument with FilePath
Export-Toml Write object or TomlDocument to file (supports -WhatIf)

Architecture

  • Parsing engine: Tomlyn v2.0.0 — a conformant .NET TOML 1.0.0 library loaded from src/assemblies/Tomlyn.dll
  • Public output type: TomlDocument class with Data ([OrderedDictionary]) and FilePath ([string])
  • Private helpers: ConvertFrom-TomlynValue/Table/DateTime + ConvertTo-TomlynValue/Table/Array — all with comment-based help
  • Structure: follows Process-PSModule layout exactly

TOML type mapping

TOML type PowerShell type
String [string]
Integer [long]
Float [double]
Boolean [bool]
Offset date-time [DateTimeOffset]
Local date-time [DateTime] (Kind=Unspecified)
Local date [DateTime] (00:00:00)
Local time [TimeSpan]
Array [object[]]
Table / Inline table [ordered] hashtable
Array of tables [object[]] of hashtables

Tests: 116/116 passing

  • ConvertFrom-Toml.Tests.ps1 — 63 tests covering full TOML 1.0.0 spec
  • ConvertTo-Toml.Tests.ps1 — 26 tests for serialization + round-trips
  • Import-Toml.Tests.ps1 — 13 tests for file import
  • Export-Toml.Tests.ps1 — 14 tests for file export + WhatIf + encoding
  • tests/data/ — 9 TOML fixture files

PSScriptAnalyzer: 0 errors, 0 warnings

Local development

./build.ps1
Import-Module Pester -MaximumVersion 5.99 -Force
$cfg = New-PesterConfiguration; $cfg.Run.Path = './tests'; Invoke-Pester -Configuration $cfg

- Add ConvertFrom-Toml, ConvertTo-Toml, Import-Toml, Export-Toml public commands
- Add TomlDocument class with Data (OrderedDictionary) and FilePath properties
- Add private helpers: ConvertFrom-TomlDateTime, ConvertFrom-TomlynTable,
  ConvertFrom-TomlynValue, ConvertTo-TomlynArray, ConvertTo-TomlynTable,
  ConvertTo-TomlynValue
- Back with Tomlyn v2.0.0 (.NET TOML library) via src/assemblies/Tomlyn.dll
- Enforce TOML 1.0.0 duplicate key and table redefinition rules via
  SyntaxParser.ParseStrict before deserializing
- Map all 8 TOML types to PowerShell types (string, long, double, bool,
  DateTimeOffset, DateTime, TimeSpan, OrderedDictionary/object[])
- Add 116 Pester tests covering spec compliance, round-trips, file I/O,
  error handling, and all TOML 1.0.0 type categories
- Add build.ps1 for local module assembly and test running
- Add tests/bootstrap.ps1 for test module import
- Add tests/data/ with 9 TOML fixture files
- Update README.md with type mapping table, command reference, usage examples
- Update examples/General.ps1 with comprehensive usage examples
- Remove template placeholder files (LsonLib.dll, format/type XMLs,
  sample modules/scripts/variables)
- Fix PSScriptAnalyzer warnings: UTF-8 BOM, indentation consistency

PSScriptAnalyzer: 0 errors, 0 warnings
Tests: 116/116 pass

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown

Super-linter summary

Language Validation result
CHECKOV Pass ✅
GITHUB_ACTIONS Pass ✅
GITLEAKS Pass ✅
GIT_MERGE_CONFLICT_MARKERS Pass ✅
MARKDOWN Fail ❌
NATURAL_LANGUAGE Pass ✅
POWERSHELL Fail ❌
PRE_COMMIT Pass ✅
SPELL_CODESPELL Pass ✅
TRIVY Pass ✅
YAML Pass ✅

Super-linter detected linting errors

For more information, see the GitHub Actions workflow run

Powered by Super-linter

MARKDOWN
/github/workspace/README.md:101:22 error MD060/table-column-style Table column style [Table pipe does not align with header for style "aligned"]
POWERSHELL

�[32;1mRuleName                           �[0m�[32;1m Severity    �[0m�[32;1m ScriptName�[0m�[32;1m Line �[0m�[32;1m Message�[0m
�[32;1m--------                           �[0m �[32;1m--------    �[0m �[32;1m----------�[0m �[32;1m---- �[0m �[32;1m-------�[0m
PSUseOutputTypeCorrectly            Information  ConvertTo- 40    The cmdlet 'C
                                                 TomlynArra       onvertTo-Toml
                                                 y.ps1            ynArray' retu
                                                                  rns an object
                                                                   of type 'Sys
                                                                  tem.Object[]'
                                                                   but this typ
                                                                  e is not decl
                                                                  ared in the O
                                                                  utputType att
                                                                  ribute.


�[32;1mRuleName                           �[0m�[32;1m Severity    �[0m�[32;1m ScriptName�[0m�[32;1m Line �[0m�[32;1m Message�[0m
�[32;1m--------                           �[0m �[32;1m--------    �[0m �[32;1m----------�[0m �[32;1m---- �[0m �[32;1m-------�[0m
PSUseOutputTypeCorrectly            Information  ConvertTo- 54    The cmdlet 'C
                                                 TomlynTabl       onvertTo-Toml
                                                 e.ps1            ynTable' retu
                                                                  rns an object
                                                                   of type 'Sys
                                                                  tem.Object[]'
                                                                   but this typ
                                                                  e is not decl
                                                                  ared in the O
                                                                  utputType att
                                                                  ribute.


�[32;1mRuleName                           �[0m�[32;1m Severity    �[0m�[32;1m ScriptName�[0m�[32;1m Line �[0m�[32;1m Message�[0m
�[32;1m--------                           �[0m �[32;1m--------    �[0m �[32;1m----------�[0m �[32;1m---- �[0m �[32;1m-------�[0m
PSUseOutputTypeCorrectly            Information  ConvertTo- 101   The cmdlet 'C
                                                 TomlynValu       onvertTo-Toml
                                                 e.ps1            ynValue' retu
                                                                  rns an object
                                                                   of type 'Sys
                                                                  tem.Int64' bu
                                                                  t this type i
                                                                  s not declare
                                                                  d in the Outp
                                                                  utType attrib
                                                                  ute.
PSUseOutputTypeCorrectly            Information  ConvertTo- 105   The cmdlet 'C
                                                 TomlynValu       onvertTo-Toml
                                                 e.ps1            ynValue' retu
                                                                  rns an object
                                                                   of type 'Sys
                                                                  tem.Double' b
                                                                  ut this type
                                                                  is not declar
                                                                  ed in the Out
                                                                  putType attri
                                                                  bute.
PSUseOutputTypeCorrectly            Information  ConvertTo- 116   The cmdlet 'C
                                                 TomlynValu       onvertTo-Toml
                                                 e.ps1            ynValue' retu
                                                                  rns an object
                                                                   of type 'Sys
                                                                  tem.Object[]'
                                                                   but this typ
                                                                  e is not decl
                                                                  ared in the O
                                                                  utputType att
                                                                  ribute.
PSUseOutputTypeCorrectly            Information  ConvertTo- 123   The cmdlet 'C
                                                 TomlynValu       onvertTo-Toml
                                                 e.ps1            ynValue' retu
                                                                  rns an object
                                                                   of type 'Sys
                                                                  tem.Object[]'
                                                                   but this typ
                                                                  e is not decl
                                                                  ared in the O
                                                                  utputType att
                                                                  ribute.


�[32;1mRuleName                           �[0m�[32;1m Severity    �[0m�[32;1m ScriptName�[0m�[32;1m Line �[0m�[32;1m Message�[0m
�[32;1m--------                           �[0m �[32;1m--------    �[0m �[32;1m----------�[0m �[32;1m---- �[0m �[32;1m-------�[0m
PSAvoidUsingPositionalParameters    Information  bootstrap. 12    Cmdlet 'Join-
                                                 ps1              Path' has pos
                                                                  itional param
                                                                  eter. Please
                                                                  use named par
                                                                  ameters inste
                                                                  ad of positio
                                                                  nal parameter
                                                                  s when callin
                                                                  g a command.


�[32;1mRuleName                           �[0m�[32;1m Severity    �[0m�[32;1m ScriptName�[0m�[32;1m Line �[0m�[32;1m Message�[0m
�[32;1m--------                           �[0m �[32;1m--------    �[0m �[32;1m----------�[0m �[32;1m---- �[0m �[32;1m-------�[0m
PSAvoidUsingWriteHost               Warning      build.ps1  105   File 'build.p
                                                                  s1' uses Writ
                                                                  e-Host. Avoid
                                                                   using Write-
                                                                  Host because
                                                                  it might not
                                                                  work in all h
                                                                  osts, does no
                                                                  t work when t
                                                                  here is no ho
                                                                  st, and (prio
                                                                  r to PS 5.0)
                                                                  cannot be sup
                                                                  pressed, capt
                                                                  ured, or redi
                                                                  rected. Inste
                                                                  ad, use Write
                                                                  -Output, Writ
                                                                  e-Verbose, or
                                                                   Write-Inform
                                                                  ation.
PSAvoidUsingWriteHost               Warning      build.ps1  106   File 'build.p
                                                                  s1' uses Writ
                                                                  e-Host. Avoid
                                                                   using Write-
                                                                  Host because
                                                                  it might not
                                                                  work in all h
                                                                  osts, does no
                                                                  t work when t
                                                                  here is no ho
                                                                  st, and (prio
                                                                  r to PS 5.0)
                                                                  cannot be sup
                                                                  pressed, capt
                                                                  ured, or redi
                                                                  rected. Inste
                                                                  ad, use Write
                                                                  -Output, Writ
                                                                  e-Verbose, or
                                                                   Write-Inform
                                                                  ation.
PSUseBOMForUnicodeEncodedFile       Warning      build.ps1        Missing BOM e
                                                                  ncoding for n
                                                                  on-ASCII enco
                                                                  ded file 'bui
                                                                  ld.ps1'
PSUseConsistentWhitespace           Warning      build.ps1  19    Use space bef
                                                                  ore and after
                                                                   binary and a
                                                                  ssignment ope
                                                                  rators.
PSUseConsistentWhitespace           Warning      build.ps1  20    Use space bef
                                                                  ore and after
                                                                   binary and a
                                                                  ssignment ope
                                                                  rators.
PSUseConsistentWhitespace           Warning      build.ps1  21    Use space bef
                                                                  ore and after
                                                                   binary and a
                                                                  ssignment ope
                                                                  rators.
PSAvoidUsingPositionalParameters    Information  build.ps1  21    Cmdlet 'Join-
                                                                  Path' has pos
                                                                  itional param
                                                                  eter. Please
                                                                  use named par
                                                                  ameters inste
                                                                  ad of positio
                                                                  nal parameter
                                                                  s when callin
                                                                  g a command.


�[32;1mRuleName                           �[0m�[32;1m Severity    �[0m�[32;1m ScriptName�[0m�[32;1m Line �[0m�[32;1m Message�[0m
�[32;1m--------                           �[0m �[32;1m--------    �[0m �[32;1m----------�[0m �[32;1m---- �[0m �[32;1m-------�[0m
PSAlignAssignmentStatement          Warning      General.ps 29    Assignment st
                                                 1                atements are
                                                                  not aligned
PSAlignAssignmentStatement          Warning      General.ps 30    Assignment st
                                                 1                atements are
                                                                  not aligned
PSAlignAssignmentStatement          Warning      General.ps 31    Assignment st
                                                 1                atements are
                                                                  not aligned
PSAlignAssignmentStatement          Warning      General.ps 32    Assignment st
                                                 1                atements are
                                                                  not aligned
PSUseConsistentIndentation          Warning      General.ps 29    Indentation n
                                                 1                ot consistent
PSUseConsistentIndentation          Warning      General.ps 30    Indentation n
                                                 1                ot consistent
PSUseConsistentIndentation          Warning      General.ps 31    Indentation n
                                                 1                ot consistent
PSUseConsistentIndentation          Warning      General.ps 32    Indentation n
                                                 1                ot consistent
PSUseConsistentIndentation          Warning      General.ps 33    Indentation n
                                                 1                ot consistent
PSUseConsistentIndentation          Warning      General.ps 34    Indentation n
                                                 1                ot consistent
PSUseConsistentIndentation          Warning      General.ps 35    Indentation n
                                                 1                ot consistent
PSUseConsistentIndentation          Warning      General.ps 36    Indentation n
                                                 1                ot consistent
PSUseConsistentIndentation          Warning      General.ps 37    Indentation n
                                                 1                ot consistent
PSAvoidUsingWriteHost               Warning      General.ps 38    File 'General
                                                 1                .ps1' uses Wr
                                                                  ite-Host. Avo
                                                                  id using Writ
                                                                  e-Host becaus
                                                                  e it might no
                                                                  t work in all
                                                                   hosts, does
                                                                  not work when
                                                                   there is no
                                                                  host, and (pr
                                                                  ior to PS 5.0
                                                                  ) cannot be s
                                                                  uppressed, ca
                                                                  ptured, or re
                                                                  directed. Ins
                                                                  tead, use Wri
                                                                  te-Output, Wr
                                                                  ite-Verbose,
                                                                  or Write-Info
                                                                  rmation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant