Skip to content

Commit a93f2b5

Browse files
authored
Merge pull request #1320 from SteveL-MSFT/trywhich-doc
Fix doc for `tryWhich()` function
2 parents c3a77ce + f311a9f commit a93f2b5

File tree

1 file changed

+38
-38
lines changed

1 file changed

+38
-38
lines changed

docs/reference/schemas/config/functions/tryWhich.md

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ title: tryWhich
77

88
## Synopsis
99

10-
Looks for an executable in the `PATH` environment variable and returns the full path to the first
10+
Looks for an executable in the `PATH` environment variable and returns the full path to the first
1111
matching executable or null if not found.
1212

1313
## Syntax
@@ -18,19 +18,19 @@ tryWhich(<commandName>)
1818

1919
## Description
2020

21-
The `tryWhich()` function searches for an executable in the `PATH` environment variable and returns
22-
the full path to the first matching executable if found. If the executable isn't discoverable, the
21+
The `tryWhich()` function searches for an executable in the `PATH` environment variable and returns
22+
the full path to the first matching executable if found. If the executable isn't discoverable, the
2323
function returns `null` instead of generating an error.
2424

2525
This function is useful for:
2626

27-
- Checking whether a required command-line tool is available before invoking it.
28-
- Conditionally configuring resources based on available system tools.
29-
- Validating prerequisites in configurations.
27+
- Checking whether a required command-line tool is available before invoking it.
28+
- Conditionally configuring resources based on available system tools.
29+
- Validating prerequisites in configurations.
3030
- Finding the exact path to executables for use in scripts or commands.
3131

32-
The function searches the `PATH` in the same way the operating system would when executing a
33-
command. On Windows, it automatically checks for common executable extensions, like `.exe`, `.cmd`,
32+
The function searches the `PATH` in the same way the operating system would when executing a
33+
command. On Windows, it automatically checks for common executable extensions, like `.exe`, `.cmd`,
3434
and `.bat`, if no extension is provided.
3535

3636
Unlike a strict path lookup that would fail if the executable is missing, `tryWhich()`
@@ -53,11 +53,11 @@ resources:
5353
properties:
5454
output:
5555
gitPath: "[tryWhich('git')]"
56-
hasGit: >-
57-
[if(
58-
equals(tryWhich('git'), null()),
59-
false(),
60-
true()
56+
hasGit: >-
57+
[if(
58+
equals(tryWhich('git'), null()),
59+
false(),
60+
true()
6161
)]
6262
```
6363
@@ -94,11 +94,11 @@ resources:
9494
type: Microsoft.DSC.Debug/Echo
9595
properties:
9696
output:
97-
pythonPath: >-
98-
[coalesce(
99-
tryWhich('python3'),
100-
tryWhich('python'),
101-
'/usr/bin/python'
97+
pythonPath: >-
98+
[coalesce(
99+
tryWhich('python3'),
100+
tryWhich('python'),
101+
'/usr/bin/python'
102102
)]
103103
```
104104

@@ -118,9 +118,9 @@ messages: []
118118
hadErrors: false
119119
```
120120

121-
In this example, the function first looks for `python3` in the `PATH` environmental variable. If
122-
that executable isn't discovered, it then looks for `python`. If neither executable is discovered,
123-
it falls back to the specified default value, `/usr/bin/python3`.
121+
In this example, the function first looks for `python3` in the `PATH` environmental variable. If
122+
that executable isn't discovered, it then looks for `python`. If neither executable is discovered,
123+
it falls back to the specified default value, `/usr/bin/python`.
124124

125125
### Example 3 - Validate multiple prerequisites
126126

@@ -139,11 +139,11 @@ resources:
139139
docker: "[tryWhich('docker')]"
140140
kubectl: "[tryWhich('kubectl')]"
141141
helm: "[tryWhich('helm')]"
142-
allFound: >-
143-
[and(
144-
not(equals(tryWhich('docker'), null())),
145-
not(equals(tryWhich('kubectl'), null())),
146-
not(equals(tryWhich('helm'), null()))
142+
allFound: >-
143+
[and(
144+
not(equals(tryWhich('docker'), null())),
145+
not(equals(tryWhich('kubectl'), null())),
146+
not(equals(tryWhich('helm'), null()))
147147
)]
148148
```
149149

@@ -174,7 +174,7 @@ not found, so `allFound` is `false`.
174174

175175
### commandName
176176

177-
The name of the executable to locate. On Windows, it automatically checks for common executable
177+
The name of the executable to locate. On Windows, it automatically checks for common executable
178178
extensions, like `.exe`, `.cmd`, and `.bat`, if no extension is provided.
179179

180180
```yaml
@@ -185,7 +185,7 @@ Position: 1
185185

186186
## Output
187187

188-
Returns the full path to the first matching executable as a string if found in the system PATH.
188+
Returns the full path to the first matching executable as a string if found in the system PATH.
189189
Returns `null` if the executable is not found.
190190

191191
```yaml
@@ -194,21 +194,21 @@ Type: string or null
194194

195195
## Error conditions
196196

197-
The function returns `null` instead of generating errors when the executable isn't found.
197+
The function returns `null` instead of generating errors when the executable isn't found.
198198

199199
The function only returns an error when the input isn't a string.
200200

201201
## Notes
202202

203-
- The function searches the `PATH` environment variable in the same order as the operating system.
204-
- On Windows, the function automatically checks for the executable with common extensions, like
205-
`.exe`, `.cmd`, and `.bat`, when the input string doesn't define an extension. For example, if
206-
the input is `dsc`, the function would return `dsc.exe` if available in `PATH`.
207-
- The function returns `null` when the executable isn't found instead of raising an error.
208-
- The function always returns the absolute path to a discovered executable.
209-
- Use with [`if()`][00] or [`coalesce()`][01] for conditional logic based on tool availability.
210-
- The function searches for the executable case-insensitively on Windows and case-sensitively on
211-
other platforms.
203+
- The function searches the `PATH` environment variable in the same order as the operating system.
204+
- On Windows, the function automatically checks for the executable with common extensions, like
205+
`.exe`, `.cmd`, and `.bat`, when the input string doesn't define an extension. For example, if
206+
the input is `dsc`, the function would return `dsc.exe` if available in `PATH`.
207+
- The function returns `null` when the executable isn't found instead of raising an error.
208+
- The function always returns the absolute path to a discovered executable.
209+
- Use with [`if()`][00] or [`coalesce()`][01] for conditional logic based on tool availability.
210+
- The function searches for the executable case-insensitively on Windows and case-sensitively on
211+
other platforms.
212212
- The function resolves symbolic links to their target paths.
213213

214214
## Related functions

0 commit comments

Comments
 (0)