Permalink
Browse files

Wrap main() function calls with a helper function

For now, it initializes logging and runs main() with the arguments from
sys.argv, exiting with the function return code.
  • Loading branch information...
glandium committed Mar 2, 2017
1 parent 8934ad9 commit be75326d56a77f84037c94bb91ff8dddacc7329e
Showing with 9 additions and 10 deletions.
  1. +5 −0 cinnabar/util.py
  2. +2 −7 git-cinnabar
  3. +2 −3 git-remote-hg
View
@@ -468,3 +468,8 @@ def __set__(self, obj, value):
# If the class has a "from_obj" static or class method, use it.
# Otherwise, just use cls(value)
self.values[obj] = getattr(self.cls, 'from_obj', self.cls)(value)
+
+
+def run(func):
+ init_logging()
+ sys.exit(func(sys.argv[1:]))
View
@@ -5,13 +5,8 @@ import sys
sys.path.append(os.path.join(os.path.dirname(__file__), 'pythonlib'))
from cinnabar.cmd import CLI
-from cinnabar.util import init_logging
-
-
-def main(argv):
- init_logging()
- return CLI.run(argv)
+from cinnabar.util import run
if __name__ == '__main__':
- sys.exit(main(sys.argv[1:]))
+ run(CLI.run)
View
@@ -12,7 +12,7 @@ from cinnabar.githg import (
from cinnabar.hg.repo import Remote
import logging
from cinnabar.remote_helper import GitRemoteHelper
-from cinnabar.util import init_logging
+from cinnabar.util import run
def main(args):
@@ -21,7 +21,6 @@ def main(args):
# the calling git process won't recognize in our answers.
import msvcrt
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
- init_logging()
assert len(args) == 2
remote = Remote(*args)
@@ -38,4 +37,4 @@ def main(args):
if __name__ == '__main__':
- sys.exit(main(sys.argv[1:]))
+ run(main)

0 comments on commit be75326

Please sign in to comment.