Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/pr-bash-examples-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ jobs:
version-injector dist/script.sh --style sh --version "${{ env.STAMPED_VERSION }}"
version-injector dist/script.ps1 --style ps1 --version "${{ env.STAMPED_VERSION }}"

- name: Create script alias for Leia examples
shell: bash
run: ln -sf script.sh dist/script

- name: Put prepared script on PATH
shell: bash
run: echo "$PWD/dist" >> "$GITHUB_PATH"
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/release-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ jobs:
actual="$(bash ./dist/script.sh --version)"
printf 'actual=%s\n' "$actual"
test "$actual" = "${{ env.STAMPED_VERSION }}"
help_output="$(bash ./dist/script.sh --help)"
printf '%s\n' "$help_output" | grep -E 'Usage: .*script\.sh '

release-powershell:
runs-on: windows-2025
Expand Down Expand Up @@ -77,3 +79,7 @@ jobs:
if ($version -ne "${{ env.STAMPED_VERSION }}") {
throw "expected version ${{ env.STAMPED_VERSION }}, got $version"
}
$help = & ./dist/script.ps1 -Help
if (-not ($help | Select-String -Pattern 'Usage: .*script\.ps1 ' -Quiet)) {
throw 'expected help output to mention script.ps1'
}
11 changes: 7 additions & 4 deletions examples/cli-contract-bash/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
# Script Bash CLI Contract Example

This example keeps coverage on the Bash-facing contract of `script.sh`: help output and version
This example keeps coverage on the Bash-facing contract of `script`: help output and version
output.

## Testing

```bash
# should show the debug flag in help output
script.sh --help | grep -- '--debug'
script --help | grep -- '--debug'

# should show the version flag in help output
script.sh --help | grep -- '--version'
script --help | grep -- '--version'

# should show the invoked command name in usage output
script --help | grep -E 'Usage: .*script '

# should print a version string
test -n "$(script.sh --version)"
test -n "$(script --version)"
```
11 changes: 7 additions & 4 deletions examples/cli-contract-powershell/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
# Script PowerShell CLI Contract Example

This example keeps coverage on the PowerShell-facing contract of `script.ps1`: help output and
This example keeps coverage on the PowerShell-facing contract of `script`: help output and
version output.

## Testing

```powershell
# should show the debug flag in help output
& script.ps1 -Help | Select-String -Pattern '-Debug'
script -Help | Select-String -Pattern '-Debug'

# should show the version flag in help output
& script.ps1 -Help | Select-String -Pattern '-Version'
script -Help | Select-String -Pattern '-Version'

# should show the invoked command name in usage output
script -Help | Select-String -Pattern 'Usage: .*script '

# should print a version string
$version = & script.ps1 -Version
$version = script -Version
if ([string]::IsNullOrWhiteSpace($version)) { throw 'expected version output' }
```
6 changes: 3 additions & 3 deletions examples/minimal-bash/README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# Script Bash Minimal Example

This example is the smallest markdown-first smoke test for `script.sh`. It runs the default
This example is the smallest markdown-first smoke test for `script`. It runs the default
no-argument flow and verifies the placeholder output from the prepared `dist/script.sh` artifact.

## Setup

```bash
# should run the default placeholder flow
script.sh > run.log 2>&1
script > run.log 2>&1
```

## Testing

```bash
# should print the placeholder execution message
grep -F 'Replace the body of script.sh with your project logic.' run.log
grep -F 'Replace the body of script with your project logic.' run.log
```

## Destroy tests
Expand Down
6 changes: 3 additions & 3 deletions examples/minimal-powershell/README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# Script PowerShell Minimal Example

This example is the smallest markdown-first smoke test for `script.ps1`. It runs the default
This example is the smallest markdown-first smoke test for `script`. It runs the default
no-argument flow and verifies the placeholder output from the prepared `dist/script.ps1` artifact.

## Setup

```powershell
# should run the default placeholder flow
script.ps1 | Set-Content -Path run.log
script | Set-Content -Path run.log
```

## Testing

```powershell
# should print the placeholder execution message
Get-Content run.log | Select-String -Pattern 'Replace the body of script.ps1 with your project logic.'
Get-Content run.log | Select-String -Pattern 'Replace the body of script with your project logic.'
```

## Destroy tests
Expand Down
14 changes: 13 additions & 1 deletion script.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,19 @@ param(
Set-StrictMode -Version 3
$ErrorActionPreference = 'Stop'

$CLI_NAME = if ($PSCommandPath) { Split-Path -Leaf $PSCommandPath } else { $MyInvocation.MyCommand.Name }
$CLI_NAME = if (
-not [string]::IsNullOrWhiteSpace($MyInvocation.InvocationName) -and
$MyInvocation.InvocationName -notin @('.', '&') -and
$MyInvocation.InvocationName -notmatch '^(?:pwsh|powershell)(?:\.exe)?$'
) {
Split-Path -Leaf $MyInvocation.InvocationName
} elseif ($PSCommandPath) {
Split-Path -Leaf $PSCommandPath
} elseif ($MyInvocation.MyCommand.Name) {
$MyInvocation.MyCommand.Name
} else {
'script.ps1'
}
# Keep a single top-level assignment so release automation can stamp the entrypoint in place.
$SCRIPT_VERSION = if (-not [string]::IsNullOrWhiteSpace($env:SCRIPT_VERSION)) { $env:SCRIPT_VERSION } else { try { $resolved = (& git describe --tags --always --abbrev=1 2>$null | Out-String).Trim(); if ($LASTEXITCODE -eq 0 -and -not [string]::IsNullOrWhiteSpace($resolved)) { $resolved } else { '0.0.0-dev' } } catch { '0.0.0-dev' } }
$ESCAPE = [char]27
Expand Down
10 changes: 9 additions & 1 deletion script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,15 @@ tty_reset="$(tty_escape 0)"
tty_tp="$(tty_escape '38;2;0;200;138')"
tty_ts="$(tty_escape '38;2;219;39;119')"

CLI_NAME="${0##*/}"
CLI_NAME_SOURCE="${BASH_SOURCE[0]:-${0}}"
CLI_NAME="${CLI_NAME_SOURCE##*/}"

case "${CLI_NAME}" in
'' | stdin | bash | -bash | sh | -sh)
CLI_NAME="script.sh"
;;
esac

# Keep a single top-level assignment so release automation can stamp the entrypoint in place.
SCRIPT_VERSION="${SCRIPT_VERSION:-$(git describe --tags --always --abbrev=1 2>/dev/null || printf '%s' '0.0.0-dev')}"

Expand Down