Skip to content

Commit 5a883c4

Browse files
authored
feat: add powershell deps/var/res docs (windmill-labs#439)
1 parent ad28d10 commit 5a883c4

File tree

5 files changed

+41
-9
lines changed

5 files changed

+41
-9
lines changed

docs/advanced/6_imports/index.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,20 @@ script and hence there is no need for any additional steps.
125125

126126
e.g:
127127

128-
```
128+
```go
129129
import (
130130
"rsc.io/quote"
131131
wmill "github.com/windmill-labs/windmill-go-client"
132132
)
133133
```
134+
135+
## Imports in PowerShell
136+
137+
For PowerShell, imports are parsed when the script is run and modules are automatically installed if they are not found in the cache.
138+
139+
e.g.:
140+
141+
```powershell
142+
Import-Module -Name MyModule
143+
```
144+

docs/core_concepts/2_variables_and_secrets/index.mdx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,13 @@ curl -s -H "Authorization: Bearer $WM_TOKEN" \
186186
| jq -r .value
187187
```
188188

189-
The last example is in bash and showcase well how it works under the hood: It fetches the secret from the API using the job's permissions through the ephemeral token passed as environment variable to the job.
189+
PowerShell:
190+
191+
```powershell
192+
$Headers = @{
193+
"Authorization" = "Bearer $Env:WM_TOKEN"
194+
}
195+
Invoke-RestMethod -Headers $Headers -Uri "$Env:BASE_INTERNAL_URL/api/w/$Env:WM_WORKSPACE/variables/get/u/user/foo"
196+
```
197+
198+
The last examples in bash and PowerShell showcase well how it works under the hood: It fetches the secret from the API using the job's permissions through the ephemeral token passed as an environment variable to the job.

docs/core_concepts/3_resources_and_types/index.mdx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,13 @@ curl -s -H "Authorization: Bearer $WM_TOKEN" \
208208
| jq -r .value
209209
```
210210

211+
PowerShell:
212+
213+
```powershell
214+
$Headers = @{
215+
"Authorization" = "Bearer $Env:WM_TOKEN"
216+
}
217+
Invoke-RestMethod -Headers $Headers -Uri "$Env:BASE_INTERNAL_URL/api/w/$Env:WM_WORKSPACE/resources/get/u/user/foo"
218+
```
219+
211220
![Fetch resource](./fetch_resource.png.webp)

docs/getting_started/0_scripts_quickstart/4_bash_quickstart/index.mdx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ fi
6565
</TabItem>
6666
<TabItem value="powershell" label="PowerShell" attributes={{className: "text-xs p-4 !mt-0 !ml-0"}}>
6767

68-
```ts
68+
```powershell
6969
param($url = "default value")
7070
7171
$status_code = (Invoke-WebRequest -Uri $url -Method Get).StatusCode
@@ -158,24 +158,26 @@ echo "Hello $msg"
158158

159159
In Bash, the arguments are inferred from the arguments requiring a $1, $2, $3. Default arguments can be specified using the syntax above: `dflt="${2:-default value}"`.
160160

161-
The command `echo` allows you to return the result, which might be useful if the script is used in a [flow](../../../flows/1_flow_editor.mdx) or [app](../../../apps/0_app_editor/index.mdx) to pass its result on.
161+
The last line of the output, here `echo "Hello $msg"`, is the return value, which might be useful if the script is used in a [flow](../../../flows/1_flow_editor.mdx) or [app](../../../apps/0_app_editor/index.mdx) to pass its result on.
162162

163163
### PowerShell
164164

165-
As we picked `PowerShell` for this example, Windmill provided some Bash
165+
As we picked `PowerShell` for this example, Windmill provided some PowerShell
166166
boilerplate. Let's take a look:
167167

168-
```bash
168+
```powershell
169169
param($Msg, $Dflt = "default value", [int]$Nb = 3)
170170
171+
# Import-Module MyModule
172+
171173
# the last line of the stdout is the return value
172174
Write-Output "Hello $Msg"
173175
```
174176

175-
In PowerShell, the arguments are inferred from the arguments requiring a "$" preceding its name.
177+
In PowerShell, the arguments are inferred from the param instruction. It has to be first in the script.
176178
Default arguments can be specified using the syntax above: `$argument_name = "Its default value"`.
177179

178-
The command `Write-Output` allows you to return the result, which might be useful if the script is used in a [flow](../../../flows/1_flow_editor.mdx) or [app](../../../apps/0_app_editor/index.mdx) to pass its result on.
180+
The last line of the output, here `Write-Output "Hello $Msg"`, is the return value, which might be useful if the script is used in a [flow](../../../flows/1_flow_editor.mdx) or [app](../../../apps/0_app_editor/index.mdx) to pass its result on.
179181

180182
## Instant Preview & Testing
181183

docusaurus.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ const config = {
157157
},
158158
prism: {
159159
theme: lightCodeTheme,
160-
darkTheme: darkCodeTheme
160+
darkTheme: darkCodeTheme,
161+
additionalLanguages: ['powershell']
161162
},
162163
colorMode: {
163164
defaultMode: 'dark',

0 commit comments

Comments
 (0)