~cloudbaseit/charms/win2012r2/drupal-iis/trunk

« back to all changes in this revision

Viewing changes to lib/Modules/powershell-yaml/README.md

  • Committer: Ionut Balutoiu
  • Date: 2016-12-23 12:55:39 UTC
  • Revision ID: ibalutoiu@cloudbasesolutions.com-20161223125539-j795kbynab3uflha
Added charm code

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# powershell-yaml
 
2
 
 
3
This powershell module is a thin wrapper on top of [YamlDotNet](https://github.com/aaubry/YamlDotNet "YamlDotNet") that serializes and un-serializes simple powershell objects to and from YAML. It was tested on powershell versions 4 and 5 and supports [Nano Server](https://technet.microsoft.com/en-us/library/mt126167.aspx Nano).
 
4
 
 
5
The ```lib``` folder contains the YamlDotNet assemblies. They are not really required, just a fall-back in case your system does not already have them installed and loaded. Feel free to remove the ```lib``` folder if you prefer to add the required assemblies yourself.
 
6
 
 
7
## ConvertTo-Yaml
 
8
 
 
9
```powershell
 
10
Import-Module powershell-yaml
 
11
 
 
12
PS C:\> $yaml = ConvertTo-Yaml @{"hello"="world"; "anArray"=@(1,2,3); "nested"=@{"array"=@("this", "is", "an", "array")}}
 
13
PS C:\> $yaml
 
14
anArray:
 
15
- 1
 
16
- 2
 
17
- 3
 
18
nested:
 
19
  array:
 
20
  - this
 
21
  - is
 
22
  - an
 
23
  - array
 
24
hello: world
 
25
```
 
26
 
 
27
## ConvertFrom-Yaml
 
28
 
 
29
### Single YAML document
 
30
 
 
31
```powershell
 
32
Import-Module powershell-yaml
 
33
 
 
34
PS C:\> $yaml = @"
 
35
anArray:
 
36
- 1
 
37
- 2
 
38
- 3
 
39
nested:
 
40
  array:
 
41
  - this
 
42
  - is
 
43
  - an
 
44
  - array
 
45
hello: world
 
46
"@
 
47
 
 
48
PS C:\> $obj = ConvertFrom-Yaml $yaml
 
49
PS C:\> $obj
 
50
 
 
51
Name                           Value
 
52
----                           -----
 
53
anArray                        {1, 2, 3}
 
54
nested                         {array}
 
55
hello                          world
 
56
 
 
57
PS C:\> $obj.GetType()
 
58
 
 
59
IsPublic IsSerial Name                                     BaseType
 
60
-------- -------- ----                                     --------
 
61
True     True     Hashtable                                System.Object
 
62
```
 
63
 
 
64
### Multiple YAML documents
 
65
 
 
66
Unserializing multiple documents results in an array representing the contents of each document. The result of this does not translate back to the same documents if you pass it back through ConvertTo-Yaml.
 
67
 
 
68
```powershell
 
69
Import-Module powershell-yaml
 
70
 
 
71
PS C:\> $yaml = @"
 
72
---
 
73
anArray:
 
74
- 1
 
75
- 2
 
76
- 3
 
77
nested:
 
78
  array:
 
79
  - this
 
80
  - is
 
81
  - an
 
82
  - array
 
83
hello: world
 
84
---
 
85
second: document
 
86
goodbye: world
 
87
"@
 
88
 
 
89
PS C:\> $obj = ConvertFrom-Yaml $yaml -AllDocuments
 
90
PS C:\> $obj
 
91
 
 
92
Name                           Value
 
93
----                           -----
 
94
anArray                        {1, 2, 3}
 
95
nested                         {array}
 
96
hello                          world
 
97
goodbye                        world
 
98
second                         document
 
99
 
 
100
PS C:\> $obj.GetType()
 
101
 
 
102
IsPublic IsSerial Name                                     BaseType
 
103
-------- -------- ----                                     --------
 
104
True     True     Object[]                                 System.Array
 
105
 
 
106
PS C:\> $obj[0]
 
107
 
 
108
Name                           Value
 
109
----                           -----
 
110
anArray                        {1, 2, 3}
 
111
nested                         {array}
 
112
hello                          world
 
113
 
 
114
PS C:\> $obj[1]
 
115
 
 
116
Name                           Value
 
117
----                           -----
 
118
goodbye                        world
 
119
second                         document
 
120
```
 
121
 
 
122
## Running the tests.
 
123
 
 
124
Before running the associated unit tests; please make sure you have
 
125
[Pester](https://github.com/pester/pester) installed, as it is the testing
 
126
framework of choice.
 
127
 
 
128
After Pester is up and running, the tests may be ran by simply entering the
 
129
tests directory and running `Invoke-Pester`:
 
130
 
 
131
```
 
132
PS C:\> git clone https://github.com/cloudbase/powershell-yaml.git $HOME\powershell-yaml
 
133
PS C:\> cd $HOME\powershell-yaml
 
134
PS C:\Users\Guest\powershell-yaml> powershell.exe -NonInteractive -Command {Invoke-Pester}
 
135
```