Skip to content

Add Import-Toml and Export-Toml file I/O functions #5

@MariusStorhaug

Description

Once ConvertFrom-Toml and ConvertTo-Toml land (#2), scripts working with .toml files will still need to combine them with Get-Content -Raw / Set-Content for every file operation. Every other PowerShell serialization format ships file-I/O wrappers — Import-Csv / Export-Csv, Import-Clixml / Export-Clixml, Import-PowerShellDataFile. Users expect the same convenience for TOML.

Request

Desired capability

$config = Import-Toml -Path Cargo.toml
$config | Export-Toml -Path Cargo.toml
$config | Export-Toml -Path Cargo.toml -NoClobber

Standard parameters

Parameter Import-Toml Export-Toml Description
-Path File path (position 0)
-LiteralPath Literal path (no wildcard expansion)
-Encoding Default utf8NoBOM (TOML spec mandates UTF-8)
-InputObject ValueFromPipeline
-NoClobber Fail if target exists
-Force Overwrite read-only files

All ConvertFrom-Toml / ConvertTo-Toml parameters pass through.

Acceptance criteria

  • Import-Toml -Path f.toml returns the same object as Get-Content f.toml -Raw | ConvertFrom-Toml
  • $o | Export-Toml -Path f.toml produces the same content as $o | ConvertTo-Toml | Set-Content f.toml
  • -NoClobber, -Force, -Encoding, -LiteralPath behave as in Export-Csv / Import-Csv
  • ShouldProcess support (-WhatIf, -Confirm) on Export-Toml
  • Round-trip via file: $o | Export-Toml -Path $f; Import-Toml -Path $f produces an equivalent object

Technical decisions

Architecture: Thin wrappers around ConvertFrom-Toml / ConvertTo-Toml. All format logic stays in the Convert functions.

Function placement: src/functions/public/Import-Toml.ps1 and src/functions/public/Export-Toml.ps1.

Parameter sets: Path (default, position 0) and LiteralPath, mirroring Import-Csv.

Encoding default: UTF-8 without BOM, per the TOML 1.0 specification which mandates UTF-8.

Aliases: Import-Tml / Export-Tml, matching the planned ConvertFrom-Tml / ConvertTo-Tml aliases in #2.

Breaking changes: None. New functions only.


Implementation plan

  • Add Import-Toml in src/functions/public/Import-Toml.ps1 with Import-Tml alias
  • Add Export-Toml in src/functions/public/Export-Toml.ps1 with Export-Tml alias
  • Add tests/Import-Toml.Tests.ps1 — basic read, -Encoding, -LiteralPath, missing file
  • Add tests/Export-Toml.Tests.ps1 — basic write, -NoClobber, -Force, -Encoding, -WhatIf, pipeline input
  • Add round-trip test through file
  • Update examples/General.ps1 and README

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions