diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0b3aaa5..e8625ad 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -32,7 +32,7 @@ jobs: runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 - name: Install Rust uses: dtolnay/rust-toolchain@stable @@ -64,7 +64,7 @@ jobs: cd ../../.. - name: Upload artifact - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v5 with: name: ${{ matrix.name }} path: ${{ matrix.name }}.* @@ -73,7 +73,7 @@ jobs: needs: build runs-on: ubuntu-latest steps: - - uses: actions/download-artifact@v4 + - uses: actions/download-artifact@v5 with: path: artifacts diff --git a/src/main.rs b/src/main.rs index febdc49..fb38646 100644 --- a/src/main.rs +++ b/src/main.rs @@ -188,6 +188,16 @@ fn run_exec(argv: &[String], dir: &Path, extra_args: &[OsString]) -> ! { fn main() { let args: Vec = env::args_os().skip(1).collect(); + // `--version` works anywhere, even outside a project, so handle it before + // looking for tasks. + if matches!( + args.first().and_then(|a| a.to_str()), + Some("--version" | "-V") + ) { + println!("nr {}", env!("CARGO_PKG_VERSION")); + return; + } + let detection = match sources::detect() { Some(d) => d, None => { diff --git a/test.sh b/test.sh index 8cd9314..a673212 100755 --- a/test.sh +++ b/test.sh @@ -362,6 +362,17 @@ else echo "(skipping uv equivalence test: uv not installed)" fi +# Test 24: --version / -V print the version, and work outside a project +VER_TMP=$(mktemp -d) +OUTPUT=$(cd "$VER_TMP" && "$BIN_ABS" --version 2>&1) +OUTPUT_SHORT=$(cd "$VER_TMP" && "$BIN_ABS" -V 2>&1) +rmdir "$VER_TMP" +if echo "$OUTPUT" | grep -qE '^nr [0-9]+\.[0-9]+\.[0-9]+' && [ "$OUTPUT" = "$OUTPUT_SHORT" ]; then + pass "--version prints version ($OUTPUT)" +else + fail "--version prints version: '$OUTPUT' / '$OUTPUT_SHORT'" +fi + echo "" echo "Results: ${PASS} passed, ${FAIL} failed"