niieani / bash-oo-framework

Bash Infinity is a modern standard library / framework / boilerplate for Bash
https://github.com/niieani/bash-oo-framework/discussions
MIT License
5.57k stars 247 forks source link

Exit code is always 0 #50

Closed bborysenko closed 6 years ago

bborysenko commented 6 years ago

Is there are way to use custom exit code?

Exit code is always 0

#!/usr/bin/env bash

source "$( cd "${BASH_SOURCE[0]%/*}" && pwd )/lib/oo-bootstrap.sh"
import util/log util/exception util/tryCatch util/namedParameters util/class

exit 1
$ ./your-script.sh; echo $?
0

Overide Exception::CleanUp()

#!/usr/bin/env bash

source "$( cd "${BASH_SOURCE[0]%/*}" && pwd )/lib/oo-bootstrap.sh"
import util/log util/exception util/tryCatch util/namedParameters util/class

Exception::CleanUp() {
  local exitVal=$?
  rm -f $__oo__storedExceptionLineFile $__oo__storedExceptionSourceFile $__oo__storedExceptionBacktraceFile $__oo__storedExceptionFile || exit 100
  exit $exitVal
}

exit 1
$ ./your-script.sh; echo $?
1

Exit command inside class

#!/usr/bin/env bash

source "$( cd "${BASH_SOURCE[0]%/*}" && pwd )/lib/oo-bootstrap.sh"
import util/log util/exception util/tryCatch util/namedParameters util/class

Exception::CleanUp() {
  local exitVal=$?
  rm -f $__oo__storedExceptionLineFile $__oo__storedExceptionSourceFile $__oo__storedExceptionBacktraceFile $__oo__storedExceptionFile || exit 10
  exit $exitVal
}

class:Webhook() {

  Webhook.gitlab() {
    echo "GITLAB"
  }

  Webhook.handle() {
    [string] id

    case "$id" in
      gitlab)
        this $id
        ;;
      *)
        echo "Error"
        exit 1
        ;;
    esac
  }
}

Type::Initialize Webhook

Webhook webhook
$var:webhook handle $1
$ ./your-script.sh gitlab; echo $?
GITLAB
0
$ ./your-script.sh slack; echo $?
Error
0
niieani commented 6 years ago

Thanks, fixed in master!