Skip to content

Commit

Permalink
Use improved enum approach
Browse files Browse the repository at this point in the history
  • Loading branch information
mhucka committed Mar 24, 2022
1 parent 6a19687 commit fa91d41
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions eprints2bags/exit_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,30 @@
file "LICENSE" for more information.
'''

from enum import IntEnum

class ExitCode(IntEnum):
success = 0
user_interrupt = 1
bad_arg = 2
no_network = 3
file_error = 4
server_error = 5
exception = 6
from aenum import Enum, MultiValue

# I adapted the clever approach posted by the author of the Python aenum
# package, Ethan Furman, to Stack Overflow on 2016-03-13 at
# https://stackoverflow.com/a/35964875/743730
# The most important bit is realizing you can define __int__().

class ExitCode(Enum):
'''Class of exit codes that this program may return.
The numeric value of a given code can be obtained by using int(). For
example, int(ExitCode.success) will produce 0.
'''

_init_ = 'value meaning'
_settings_ = MultiValue

success = 0, "success -- program completed normally"
user_interrupt = 1, "the user interrupted the program's execution"
bad_arg = 2, "encountered a bad or missing value for an option"
no_network = 3, "no network detected -- cannot proceed"
file_error = 4, "file error -- encountered a problem with a file or directory"
server_error = 5, "server error -- encountered a problem with the server"
exception = 6, "an exception or fatal error occurred"

def __int__(self):
return self.value

0 comments on commit fa91d41

Please sign in to comment.