thisismypassport / shrinko8

Shrink (minify) Pico-8 carts, as well as other tools (e..g linting, format conversion)
MIT License
92 stars 7 forks source link

argument parser acting strange (not trimming spaces?) #4

Closed pancelor closed 2 years ago

pancelor commented 2 years ago

not-working script:

#!/usr/bin/env bash

# usage:
#   ./compress.sh    # build + minify
#   ./compress.sh 1  # build only

MINIFY="--minify"
if [[ -n "$1" ]]; then
  echo "skipping minification..."
  MINIFY=""
fi

/w/shrinko8/shrinko8.py game.p8 tower.p8.png --lint --count "$MINIFY" --script compress_combine.py

when I ./compress.sh, shrinko8 runs normally. when I ./compress.sh 1, it shows the usage string and says shrinko8.py: error: unrecognized arguments:, which is unexpected (I expect it to run normally)

I assume the problem is because the command ends up having two spaces in it, which confuses the argument parser, but I haven't looked into it.

My shrinko8 commit hash is 8a4f6e0


workaround:

#!/usr/bin/env bash

# usage:
#   ./compress.sh    # build + minify
#   ./compress.sh 1  # build only

MINIFY="--minify"
if [[ -n "$1" ]]; then
  echo "skipping minification..."
  MINIFY="--count" # hacky
fi

/w/shrinko8/shrinko8.py game.p8 tower.p8.png --lint --count "$MINIFY" --script compress_combine.py
pancelor commented 2 years ago

ah my bad; when minify is empty --count "$MINIFY" --script becomes --count "" --script, and the argparser (correctly) wonders "uhhh why did you pass me an empty string there in the middle?"

removing the quotes works as expected:

#!/usr/bin/env bash

# usage:
#   ./compress.sh    # build + minify
#   ./compress.sh 1  # build only

MINIFY="--minify"
if [[ -n "$1" ]]; then
  echo "skipping minification..."
  MINIFY=""
fi

/w/shrinko8/shrinko8.py game.p8 tower.p8.png --lint --count $MINIFY --script compress_combine.py

whoops -- I should have looked into this more before opening an issue!