gitops-playground icon indicating copy to clipboard operation
gitops-playground copied to clipboard

Spinner prints "ok" on failure

Open schnatterer opened this issue 5 years ago • 4 comments

The new apply.sh looks really awesome!

One downside: when one of the initializations fails, it still prints ok and continues the initialization.

I'd prefer if it printed failed and stops the execution.

You can reproduce this by making an init function return 1 for example.

schnatterer avatar Nov 25 '20 14:11 schnatterer

You're right, it would be much better.

The current implementation is more of a workaround so that the spinner won't stop at a random character at the end of its spinning lifecycle:

[ / ] placeholder text [ - ] placeholder text [ / ] placeholder text [ \ ] placeholder text

So the [ ok ] is hard coded right now.

marekzan avatar Nov 27 '20 15:11 marekzan

Any ideas?

I tried adding the following to the end of spinner() but it doesn't work reliably, probably because the function is not allowed to wait for the process.

    set -x
    echo waiting
    wait $!
    return_code=$?
    if [ $return_code -eq 0 ]; then
      echo -e "[\e[32mok\e[0m] $info"
    else
      echo -e "[\e[31mfailed\e[0m] $info" 
    fi
    set +x

It could be a solution to only pass the command to be executed to the spinner and make it start the background process. This way, it probably would be allowed to access the process and wait for it. Not sure if this will work. Maybe we can look into it at the of the sprint :wink:

schnatterer avatar Nov 27 '20 16:11 schnatterer

Yeah, let's look into it at the end of the sprint :). So far I didn't think about a solution to this problem.

marekzan avatar Nov 27 '20 17:11 marekzan

While we're on it we could also add a debug param or env var to spinner, so we don't have to repeat all commands. Keeping our apply.sh more DRY :slightly_smiling_face:

schnatterer avatar Nov 27 '20 19:11 schnatterer