Skip to content
This repository has been archived by the owner on Jan 14, 2024. It is now read-only.

Commit

Permalink
Refactor to make testable: RiotKitDoApplication
Browse files Browse the repository at this point in the history
  • Loading branch information
blackandred committed May 8, 2020
1 parent 90b6fe0 commit fd7ced4
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions src/rkd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,25 @@ def main(self, argv: list):
if not argv[1:]:
self.print_banner_and_exit()

try:
# system wide IO instance with defaults, the :init task should override those settings
io = SystemIO()
io.silent = True
io.log_level = LOG_LEVEL_INFO
# system wide IO instance with defaults, the :init task should override those settings
io = SystemIO()
io.silent = True
io.log_level = LOG_LEVEL_INFO

# load context of components
self._ctx = ContextFactory(io).create_unified_context()
# load context of components
self._ctx = ContextFactory(io).create_unified_context()

resolver = TaskResolver(self._ctx)
executor = OneByOneTaskExecutor(self._ctx)
resolver = TaskResolver(self._ctx)
executor = OneByOneTaskExecutor(self._ctx)

# iterate over each task, parse commandline arguments
requested_tasks = CommandlineParsingHelper.create_grouped_arguments([':init'] + argv[1:])
# iterate over each task, parse commandline arguments
requested_tasks = CommandlineParsingHelper.create_grouped_arguments([':init'] + argv[1:])

# validate all tasks
resolver.resolve(requested_tasks, TaskDeclarationValidator.assert_declaration_is_valid)
# validate all tasks
resolver.resolve(requested_tasks, TaskDeclarationValidator.assert_declaration_is_valid)

# execute all tasks
resolver.resolve(requested_tasks, executor.execute)

except TaskNotFoundException as e:
print(e)
sys.exit(1)
# execute all tasks
resolver.resolve(requested_tasks, executor.execute)

executor.get_observer().execution_finished()

Expand All @@ -58,7 +53,12 @@ def print_banner_and_exit():

def main():
app = RiotKitDoApplication()
app.main(argv=sys.argv)

try:
app.main(argv=sys.argv)
except TaskNotFoundException as e:
print(e)
sys.exit(1)


if __name__ == '__main__':
Expand Down

0 comments on commit fd7ced4

Please sign in to comment.