#!/usr/bin/env python

"""
Run Steps from the command line

Exit Status
-----------
    0:  Step completed satisfactorally
    1:  General error occurred
    64: No science exists
"""

import sys

from jwst.assign_wcs.util import NoDataOnDetectorError
from jwst.stpipe import Step
import jwst

if __name__ == '__main__':

    if '--version' in sys.argv:
        sys.stdout.write(f"{jwst.__version__}\n")
        sys.exit(0)

    try:
        step = Step.from_cmdline(sys.argv[1:])

    except NoDataOnDetectorError:
        #  No science data is present on a detector. This can happen
        #  with NIRSpec and the NRS2 detector: Situations occur when no spectra
        #  disperse across both detectors.
        #
        #  Special exit status is provided so that automatic processing can detect
        #  this situation and act accordingly.
        #
        #  Full discussion: https://github.com/spacetelescope/jwst/issues/2336
        import traceback
        traceback.print_exc()
        sys.exit(64)

    except Exception:
        import traceback
        traceback.print_exc()
        sys.exit(1)
