Skip to content

Commit 0e7ddb9

Browse files
Merge pull request #981 from Gijsreyn/logical-functions-ref-docs
Add reference docs for logical functions
2 parents 8b5bca5 + 11f78c9 commit 0e7ddb9

File tree

6 files changed

+666
-0
lines changed

6 files changed

+666
-0
lines changed
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
---
2+
description: Reference for the 'and' DSC configuration document function
3+
ms.date: 01/19/2025
4+
ms.topic: reference
5+
title: and
6+
---
7+
8+
# and
9+
10+
## Synopsis
11+
12+
Returns true if all arguments are true.
13+
14+
## Syntax
15+
16+
```Syntax
17+
and(<arg1>, <arg2>, ...)
18+
```
19+
20+
## Description
21+
22+
The `and()` function evaluates if all arguments are true. It takes two or more boolean arguments
23+
and returns `true` only if every argument is `true`. If any argument is `false`, the function
24+
returns `false`.
25+
26+
This function uses short-circuit evaluation, meaning it returns `false` as soon as it encounters
27+
the first `false` argument without evaluating the remaining arguments.
28+
29+
## Examples
30+
31+
### Example 1 - Basic and operation
32+
33+
This configuration demonstrates basic usage of the `and()` function.
34+
35+
```yaml
36+
# and.example.1.dsc.config.yaml
37+
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
38+
resources:
39+
- name: Echo and result
40+
type: Microsoft.DSC.Debug/Echo
41+
properties:
42+
output: "[and(true, true)]"
43+
```
44+
45+
```bash
46+
dsc config get --file and.example.1.dsc.config.yaml
47+
```
48+
49+
```yaml
50+
results:
51+
- metadata:
52+
Microsoft.DSC:
53+
duration: PT0.1291763S
54+
name: Echo and result
55+
type: Microsoft.DSC.Debug/Echo
56+
result:
57+
actualState:
58+
output: true
59+
messages: []
60+
hadErrors: false
61+
```
62+
63+
### Example 2 - And operation with false value
64+
65+
This example shows the `and()` function returning false when one argument is false.
66+
67+
```yaml
68+
# and.example.2.dsc.config.yaml
69+
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
70+
resources:
71+
- name: Echo and result with false
72+
type: Microsoft.DSC.Debug/Echo
73+
properties:
74+
output: "[and(true, false, true)]"
75+
```
76+
77+
```bash
78+
dsc config get --file and.example.2.dsc.config.yaml
79+
```
80+
81+
```yaml
82+
results:
83+
- metadata:
84+
Microsoft.DSC:
85+
duration: PT0.0329292S
86+
name: Echo and result with false
87+
type: Microsoft.DSC.Debug/Echo
88+
result:
89+
actualState:
90+
output: false
91+
messages: []
92+
hadErrors: false
93+
```
94+
95+
### Example 3 - And operation with multiple conditions
96+
97+
This configuration uses the `and()` function with multiple boolean expressions.
98+
99+
```yaml
100+
# and.example.3.dsc.config.yaml
101+
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
102+
resources:
103+
- name: Echo complex and operation
104+
type: Microsoft.DSC.Debug/Echo
105+
properties:
106+
output: "[and(equals(5, 5), equals('hello', 'hello'), true)]"
107+
```
108+
109+
```bash
110+
dsc config get --file and.example.3.dsc.config.yaml
111+
```
112+
113+
```yaml
114+
results:
115+
- metadata:
116+
Microsoft.DSC:
117+
duration: PT0.0514415S
118+
name: Echo complex and operation
119+
type: Microsoft.DSC.Debug/Echo
120+
result:
121+
actualState:
122+
output: true
123+
messages: []
124+
hadErrors: false
125+
```
126+
127+
## Parameters
128+
129+
### arguments
130+
131+
The `and()` function requires two or more boolean arguments.
132+
133+
```yaml
134+
Type: boolean
135+
Required: true
136+
MinimumCount: 2
137+
MaximumCount: 18446744073709551615
138+
```
139+
140+
## Output
141+
142+
The `and()` function returns `true` if all arguments are `true`, otherwise it returns `false`.
143+
144+
```yaml
145+
Type: boolean
146+
```
147+
148+
<!-- Link reference definitions -->
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
---
2+
description: Reference for the 'bool' DSC configuration document function
3+
ms.date: 01/19/2025
4+
ms.topic: reference
5+
title: bool
6+
---
7+
8+
# bool
9+
10+
## Synopsis
11+
12+
Converts a string or number to a boolean value.
13+
14+
## Syntax
15+
16+
```Syntax
17+
bool(<value>)
18+
```
19+
20+
## Description
21+
22+
The `bool()` function converts a string or number to a boolean value. For string arguments,
23+
it accepts "true" (case-insensitive) which converts to `true`, and "false" (case-insensitive)
24+
which converts to `false`. For numeric arguments, zero converts to `false` and any non-zero
25+
value converts to `true`.
26+
27+
> [!NOTE]
28+
> Any string argument other than `true` or `false` (case-insensitive) will raise a DSC error.
29+
30+
## Examples
31+
32+
### Example 1 - Convert string to boolean
33+
34+
This configuration demonstrates converting string values to boolean.
35+
36+
```yaml
37+
# bool.example.1.dsc.config.yaml
38+
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
39+
resources:
40+
- name: Echo bool from string
41+
type: Microsoft.DSC.Debug/Echo
42+
properties:
43+
output:
44+
trueValue: "[bool('true')]"
45+
falseValue: "[bool('FALSE')]"
46+
```
47+
48+
```bash
49+
dsc config get --file bool.example.1.dsc.config.yaml
50+
```
51+
52+
```yaml
53+
results:
54+
- metadata:
55+
Microsoft.DSC:
56+
duration: PT0.0334711S
57+
name: Echo bool from string
58+
type: Microsoft.DSC.Debug/Echo
59+
result:
60+
actualState:
61+
output:
62+
trueValue: true
63+
falseValue: false
64+
messages: []
65+
hadErrors: false
66+
```
67+
68+
### Example 2 - Convert number to boolean
69+
70+
This example shows the `bool()` function converting numeric values to boolean.
71+
72+
```yaml
73+
# bool.example.2.dsc.config.yaml
74+
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
75+
resources:
76+
- name: Echo bool from numbers
77+
type: Microsoft.DSC.Debug/Echo
78+
properties:
79+
output:
80+
zeroIsFalse: "[bool(0)]"
81+
oneIsTrue: "[bool(1)]"
82+
negativeIsTrue: "[bool(-5)]"
83+
positiveIsTrue: "[bool(42)]"
84+
```
85+
86+
```bash
87+
dsc config get --file bool.example.2.dsc.config.yaml
88+
```
89+
90+
```yaml
91+
results:
92+
- metadata:
93+
Microsoft.DSC:
94+
duration: PT0.0323199S
95+
name: Echo bool from numbers
96+
type: Microsoft.DSC.Debug/Echo
97+
result:
98+
actualState:
99+
output:
100+
zeroIsFalse: false
101+
oneIsTrue: true
102+
negativeIsTrue: true
103+
positiveIsTrue: true
104+
messages: []
105+
hadErrors: false
106+
```
107+
108+
## Parameters
109+
110+
### value
111+
112+
The `bool()` function requires a single argument that is either a string or number.
113+
114+
For strings, valid values are:
115+
- "true" (case-insensitive) - converts to `true`
116+
- "false" (case-insensitive) - converts to `false`
117+
118+
For numbers:
119+
- 0 - converts to `false`
120+
- Any non-zero value - converts to `true`
121+
122+
```yaml
123+
Type: [string, integer]
124+
Required: true
125+
MinimumCount: 1
126+
MaximumCount: 1
127+
```
128+
129+
## Output
130+
131+
The `bool()` function returns a boolean value based on the input argument.
132+
133+
```yaml
134+
Type: boolean
135+
```
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
description: Reference for the 'false' DSC configuration document function
3+
ms.date: 01/19/2025
4+
ms.topic: reference
5+
title: false
6+
---
7+
8+
# false
9+
10+
## Synopsis
11+
12+
Returns the boolean value false.
13+
14+
## Syntax
15+
16+
```Syntax
17+
false()
18+
```
19+
20+
## Description
21+
22+
The `false()` function returns the boolean value `false`. This function takes no arguments and
23+
always returns `false`. It's useful for providing explicit boolean values in configurations
24+
or for logical operations.
25+
26+
## Examples
27+
28+
### Example 1 - Basic false value
29+
30+
This configuration demonstrates basic usage of the `false()` function.
31+
32+
```yaml
33+
# false.example.1.dsc.config.yaml
34+
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
35+
resources:
36+
- name: Echo false value
37+
type: Microsoft.DSC.Debug/Echo
38+
properties:
39+
output: "[false()]"
40+
```
41+
42+
```bash
43+
dsc config get --file false.example.1.dsc.config.yaml
44+
```
45+
46+
```yaml
47+
results:
48+
- name: Echo false value
49+
type: Microsoft.DSC.Debug/Echo
50+
result:
51+
actualState:
52+
output: false
53+
messages: []
54+
hadErrors: false
55+
```
56+
57+
## Parameters
58+
59+
The `false()` function takes no arguments.
60+
61+
```yaml
62+
Type: none
63+
Required: false
64+
MinimumCount: 0
65+
MaximumCount: 0
66+
```
67+
68+
## Output
69+
70+
The `false()` function always returns the boolean value `false`.
71+
72+
```yaml
73+
Type: boolean
74+
```
75+
76+
<!-- Link reference definitions -->

0 commit comments

Comments
 (0)