diff --git a/src/header.ps1 b/src/header.ps1 index 83ab257..52f27ac 100644 --- a/src/header.ps1 +++ b/src/header.ps1 @@ -6,36 +6,25 @@ function New-TemporaryDirectory { } $TEMPDIR = New-TemporaryDirectory -$PREFIX = "" -$VERBOSE = $false -$QUIET = $false -$UNPACK_SHELL = "" $USAGE = @" -usage: $($MyInvocation.MyCommand.Name) [options] - -Unpacks an environment packed using pixi-pack - --h, --help Print this help message and exit --o, --output-directory Where to unpack the environment --s, --shell Sets the shell [options: bash, zsh, xonsh, cmd, powershell, fish, nushell] --v, --verbose Increase logging verbosity --q, --quiet Decrease logging verbosity +Usage: $($MyInvocation.MyCommand.Name) [OPTIONS] + +Arguments: + Path to an environment packed using pixi-pack + +Options: + -o, --output-directory Where to unpack the environment. The environment will be unpacked into a subdirectory of this path [default: env] + -e, --env-name Name of the environment [default: env] + -s, --shell Sets the shell [options: bash, zsh, xonsh, cmd, powershell, fish, nushell] + -v, --verbose Increase logging verbosity + -q, --quiet Decrease logging verbosity + -h, --help Print help "@ -# Parse command-line arguments -$InputArgs = $MyInvocation.UnboundArguments -for ($i = 0; $i -lt $args.Count; $i++) { - switch ($InputArgs[$i]) { - "-o" { $PREFIX = $InputArgs[++$i] } - "--output-directory" { $PREFIX = $InputArgs[++$i] } - "-s" { $UNPACK_SHELL = $InputArgs[++$i] } - "--shell" { $UNPACK_SHELL = $InputArgs[++$i] } - "-v" { $VERBOSE = $true } - "--verbose" { $VERBOSE = $true } - "-q" { $QUIET = $true } - "--quiet" { $QUIET = $true } - "-h" { Write-Output $USAGE; exit 0 } - "--help" { Write-Output $USAGE; exit 0 } +foreach ($arg in $args) { + if ($arg -eq "-h" -or $arg -eq "--help") { + Write-Output $USAGE + exit 0 } } @@ -91,27 +80,9 @@ try { # Build the command with flags $arguments = @("unpack") +$arguments += $args | Join-String -Separator ' ' -# Use $PREFIX for output directory if it is provided -if ($PREFIX) { - $arguments += "--output-directory" - $arguments += $PREFIX -} - -# Handle verbosity/quiet flags -if ($VERBOSE) { - $arguments += "--verbose" -} elseif ($QUIET) { - $arguments += "--quiet" -} - -# Add shell flag if provided -if ($UNPACK_SHELL) { - $arguments += "--shell" - $arguments += $UNPACK_SHELL -} - -# Finally, add the path to the archive +# Add the path to the archive $arguments += $archivePath & $pixiPackPath @arguments diff --git a/src/header.sh b/src/header.sh index 6761bdc..65dbedc 100644 --- a/src/header.sh +++ b/src/header.sh @@ -2,67 +2,27 @@ set -euo pipefail TEMPDIR="$(mktemp -d)" -PREFIX="" -VERBOSE=0 -QUIET=0 -UNPACK_SHELL="" - USAGE=" -usage: $0 [options] - -Unpacks an environment packed using pixi-pack - --h, --help Print this help message and exit --o, --output-directory Where to unpack the environment --s, --shell Sets the shell [options: bash, zsh, xonsh, cmd, powershell, fish, nushell] --v, --verbose Increase logging verbosity --q, --quiet Decrease logging verbosity +Usage: $0 [OPTIONS] + +Arguments: + Path to an environment packed using pixi-pack + +Options: + -o, --output-directory Where to unpack the environment. The environment will be unpacked into a subdirectory of this path [default: env] + -e, --env-name Name of the environment [default: env] + -s, --shell Sets the shell [options: bash, zsh, xonsh, cmd, powershell, fish, nushell] + -v, --verbose Increase logging verbosity + -q, --quiet Decrease logging verbosity + -h, --help Print help " -# Parse command-line arguments -while [[ $# -gt 0 ]]; do - case "$1" in - -h) - echo "$USAGE" - exit 0 - ;; - -v) - VERBOSE=1 - shift - ;; - -o) - if [[ -n "$2" && "$2" != -* ]]; then - PREFIX="$2" - shift 2 - else - echo "Option -o requires an argument" >&2 - echo "$USAGE" >&2 - exit 1 - fi - ;; - -s) - if [[ -n "$2" && "$2" != -* ]]; then - UNPACK_SHELL="$2" - shift 2 - else - echo "Option -s requires an argument" >&2 - echo "$USAGE" >&2 - exit 1 - fi - ;; - -q) - QUIET=1 - shift - ;; - -*) - echo "Invalid option: $1" >&2 - echo "$USAGE" >&2 - exit 1 - ;; - *) - # Stop parsing options when encountering a non-option argument - break - ;; - esac + +# Check for help flag +for arg in "$@"; do + if [ "$arg" = "-h" ] || [ "$arg" = "--help" ]; then + echo "$USAGE" + exit 0 + fi done archive_begin=$(grep -anm 1 "^@@END_HEADER@@" "$0" | awk -F: '{print $1}') @@ -93,21 +53,7 @@ fi chmod +x "$TEMPDIR/pixi-pack" -VERBOSITY_FLAG="" -[ "$VERBOSE" = "1" ] && VERBOSITY_FLAG="--verbose" -[ "$QUIET" = "1" ] && VERBOSITY_FLAG="--quiet" - -OUTPUT_DIR_FLAG="" -[ -n "$PREFIX" ] && OUTPUT_DIR_FLAG="--output-directory $PREFIX" - -SHELL_FLAG="" -[ -n "$UNPACK_SHELL" ] && SHELL_FLAG="--shell $UNPACK_SHELL" - -CMD="\"$TEMPDIR/pixi-pack\" unpack $OUTPUT_DIR_FLAG $VERBOSITY_FLAG" -if [ -n "$UNPACK_SHELL" ]; then - CMD="$CMD --shell $UNPACK_SHELL" -fi -CMD="$CMD \"$TEMPDIR/archive.tar\"" +CMD="\"$TEMPDIR/pixi-pack\" unpack $@ \"$TEMPDIR/archive.tar\"" # Execute the command eval "$CMD"