Skip to content

Commit

Permalink
powershell support (#43)
Browse files Browse the repository at this point in the history
* first pass on powershell support

* add powershells to shell option list

* test concerns

* test concerns 2
  • Loading branch information
pirog committed Mar 14, 2024
1 parent 9e82f6e commit 7745b51
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 12 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/pr-leia-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
# Try a basic example
npx leia examples/basic-example.md --debug
# Try globs and ignores
npx leia "examples/**/*.md" -i "examples/basic-cmd-example.md" -i "examples/exclude-example/**/*.md" -i "examples/stdin-example.md" -i "examples/custom-headers.md" -i "examples/environment.md"
npx leia "examples/**/*.md" -i "examples/basic-cmd-example.md" -i "examples/exclude-example/**/*.md" -i "examples/stdin-example.md" -i "examples/custom-headers.md" -i "examples/environment.md" -i "examples/basic-pwsh-example.md"
# Try custom headers
npx leia examples/custom-headers.md -s Hello -t Sup -c Goodbye
# Try all other options, including legacy ones
Expand All @@ -47,4 +47,3 @@ jobs:
npx leia examples/custom-headers.md -s Blue,No,Yellow,Hello -t Sup -c Goodbye
# Assess envvars
npx leia examples/environment.md examples/basic-example.md --retry 4
8 changes: 6 additions & 2 deletions .github/workflows/pr-shell-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ jobs:
if: ${{ runner.os == 'Windows' }}
shell: bash
run: npx leia examples/basic-example.md --debug
- name: Test Windows CMD
- name: Test Windows SHELLS
if: ${{ runner.os == 'Windows' }}
run: npx leia examples/basic-cmd-example.md --debug
run: |
npx leia examples/basic-cmd-example.md --debug
npx leia examples/basic-cmd-example.md --shell cmd --debug
npx leia examples/basic-pwsh-example.md --shell pwsh --debug
npx leia examples/basic-pwsh-example.md --shell powershell --debug
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
## v1.0.0-beta.2 - [March 14, 2024](https://github.com/lando/leia/releases/tag/v1.0.0-beta.3)
## v1.0.0-beta.2 - [March 14, 2024](https://github.com/lando/leia/releases/tag/v1.0.0-beta.2)

* Fixed issue when `chai@5` shows up higher in the dependency tree [#37](https://github.com/lando/leia/issues/37)
* Added support for `powershell` and `pwsh`
* Deyarned
* Fixed issue when `chai@5` shows up higher in the dependency tree [#37](https://github.com/lando/leia/issues/37)

## v1.0.0-beta.1 - [August 19, 2023](https://github.com/lando/leia/releases/tag/v1.0.0-beta.1)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ Note: `LEIA_TEST_STAGE` can be either `setup`, `test` or `cleanup` and `LEIA_TES
* On POSIX systems it will prefer `bash` or `zsh` if available with a fallback to `sh`.
* On Windows systems it will prefer `bash` if available with a fallback to `cmd`.

You can also explicitly tell `leia` what shell to use with the `--shell` option. However, currently only `bash`, `sh`, `zsh` and `cmd` are supported options.
You can also explicitly tell `leia` what shell to use with the `--shell` option. However, currently only `bash`, `sh`, `zsh`, `cmd`, `powershell` and `pwsh` are supported options.

**In most use cases it's best to just let `leia` decide the shell to use automatically.**

Expand Down
2 changes: 1 addition & 1 deletion cli/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class LeiaCommand extends Command {
'shell': flags.string({
default: shell().binary,
description: 'the shell to use for the tests, default is autodetected',
options: ['bash', 'sh', 'zsh', 'cmd'],
options: ['bash', 'cmd', 'powershell', 'pwsh', 'sh', 'zsh', 'cmd'],
}),
'stdin': flags.boolean({
description: 'attach stdin when the test is run',
Expand Down
21 changes: 21 additions & 0 deletions examples/basic-pwsh-example.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Basic POWERSHELL Example
========================

Here is a basic example that is designed to run only on Windows with `powershell.exe` as the shell.

Testing
-------

```
# Should show envvars
Get-ChildItem Env:
# Should echo some stuff
# NOTE: Important note for the markdown file that doesnt need to be in the test description
Write-Output "some stuff"
# Should concatenate three commands together
Write-Output "some stuff"
Write-Output "yup" | Select-String -Pattern "yup"
Get-ChildItem Env:
```
21 changes: 17 additions & 4 deletions lib/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,29 @@ module.exports = (shell = userShell()) => {
switch (data.name) {
case 'bash':
return _.assign(data, {args: ['--noprofile', '--norc', '-eo', 'pipefail', '{0}']});
case 'sh':
return _.assign(data, {args: ['-e', '{0}']});
case 'zsh':
return _.assign(data, {args: ['--norcs', '-eo', 'pipefail', '{0}']});
case 'cmd':
return _.assign(data, {
binary: 'cmd.exe',
args: ['/D', '/E:ON', '/V:OFF', '/S', '/C', 'CALL', '{0}'],
extension: '.cmd',
});
case 'pwsh':
return _.assign(data, {
binary: 'pwsh.exe',
args: ['-command', '.', '{0}'],
extension: '.ps1',
});
case 'powershell':
return _.assign(data, {
binary: 'powershell.exe',
args: ['-command', '.', '{0}'],
extension: '.ps1',
});
case 'sh':
return _.assign(data, {args: ['-e', '{0}']});
case 'zsh':
return _.assign(data, {args: ['--norcs', '-eo', 'pipefail', '{0}']});

default:
return {binary: 'sh', name: 'sh', args: ['-e', '{0}'], extension: '.sh'};
}
Expand Down

0 comments on commit 7745b51

Please sign in to comment.