-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeneral.ps1
More file actions
92 lines (79 loc) · 3.49 KB
/
Copy pathGeneral.ps1
File metadata and controls
92 lines (79 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<#
.SYNOPSIS
General usage examples for the Toml module.
#>
# Import the module
Import-Module -Name 'Toml'
# ── Parse TOML string ──────────────────────────────────────────────────────
$doc = ConvertFrom-Toml -InputObject @'
[database]
host = "localhost"
port = 5432
enabled = true
tags = ["production", "primary"]
[database.credentials]
user = "admin"
'@
$doc.Data.database.host # "localhost"
$doc.Data.database.port # 5432
$doc.Data.database.enabled # True
$doc.Data.database.tags # @("production", "primary")
$doc.Data.database.credentials.user # "admin"
# ── Serialize to TOML ──────────────────────────────────────────────────────
$appData = [ordered]@{
title = 'My Application'
version = 2
debug = $false
server = [ordered]@{
host = '0.0.0.0'
port = 8080
}
features = @('auth', 'logging', 'metrics')
}
$toml = ConvertTo-Toml -InputObject $appData
Write-Output $toml
# ── Import from file ───────────────────────────────────────────────────────
# $doc = Import-Toml -Path './config.toml'
# $doc.FilePath # absolute path to the source file
# $doc.Data # [ordered] hashtable of all top-level keys
# ── Export to file ─────────────────────────────────────────────────────────
# Export-Toml -InputObject ([ordered]@{ key = 'value' }) -Path './config.toml'
# ── Round-trip: file → edit → file ────────────────────────────────────────
# $doc = Import-Toml -Path './config.toml'
# $doc.Data['version'] = 3
# Export-Toml -InputObject $doc -Path './config.toml'
# ── Normalize TOML text ────────────────────────────────────────────────────
$normalized = Format-Toml -InputObject @'
title="My App"
[server]
host="localhost"
port=8080
'@
Write-Output $normalized
# title = "My App"
#
# [server]
# host = "localhost"
# port = 8080
# ── Pipeline usage ─────────────────────────────────────────────────────────
# '[server]
# host = "localhost"' | ConvertFrom-Toml | ConvertTo-Toml
# ── All TOML scalar types ──────────────────────────────────────────────────
$types = ConvertFrom-Toml -InputObject @'
a_string = "hello"
an_integer = 42
a_float = 3.14
a_bool = true
an_offset_dt = 1979-05-27T07:32:00Z
a_local_dt = 1979-05-27T07:32:00
a_local_date = 1979-05-27
a_local_time = 07:32:00
'@
$types.Data.a_string # [string]
$types.Data.an_integer # [long]
$types.Data.a_float # [double]
$types.Data.a_bool # [bool]
$types.Data.an_offset_dt # [System.DateTimeOffset]
$types.Data.a_local_dt # [System.DateTime] (Kind=Unspecified)
$types.Data.a_local_date # [System.DateTime] (00:00:00)
$types.Data.a_local_time # [System.TimeSpan]