Commit 0731c491 authored by Dos Santos David's avatar Dos Santos David

add quit command and handle unix signals

parent d49fe683
from gogole.commands import analyze_command, eval_command, index_command, search_command
from gogole.commands import analyze_command, eval_command, index_command, search_command, quit_command
MAIN_COMMANDS_MAP = {
'analyze': analyze_command.run,
'eval': eval_command.run,
'index': index_command.run,
'search': search_command.run
'search': search_command.run,
'quit': quit_command.run,
}
def run(collection, args):
raise KeyboardInterrupt()
import argparse
import sys
import traceback
from gogole import commands
from gogole.config import COLLECTIONS
......@@ -83,6 +85,9 @@ def build_cli_search_parser(root_parser):
search_parser.set_defaults(weight_type='tf-idf')
search_parser.set_defaults(search_query_type='boolean')
def build_cli_quit_parser(root_parser):
quit_parser = root_parser.add_parser('quit', description='quit')
def build_cli_parser():
# cli parser
cli_parser = argparse.ArgumentParser(prog="", add_help=False)
......@@ -92,6 +97,7 @@ def build_cli_parser():
build_cli_eval_parser(cli_subparser)
build_cli_index_parser(cli_subparser)
build_cli_search_parser(cli_subparser)
build_cli_quit_parser(cli_subparser)
return cli_parser
......@@ -115,11 +121,21 @@ if __name__ == "__main__":
cli_parser = build_cli_parser()
while True:
print('')
raw_input = input("gogole > ")
try:
print('')
raw_input = input("gogole > ")
args = cli_parser.parse_args(raw_input.split(' '))
commands.MAIN_COMMANDS_MAP[args.main_command](collection, args)
except SystemExit:
pass
except (KeyboardInterrupt, EOFError):
print('\nBye !\n\n\n')
sys.exit(0) # exit successfuly
except:
print('\nOuuups. Something is broken :/')
print('-'*60)
print(traceback.print_exc(file=sys.stdout))
print('-'*60)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment