migrated cli functions

This commit is contained in:
ativelkov 2014-01-24 17:26:26 -08:00
parent c16eb235f7
commit da36075653

View File

@ -18,20 +18,19 @@ import re
import types import types
from json import JSONDecoder from json import JSONDecoder
from yaql.context import Context from yaql.language.context import Context
from yaql.exceptions import YaqlParsingException from yaql.language.exceptions import YaqlParsingException
import yaql import yaql
from yaql.functions.old.decorators import arg, ContextAware
from yaql.language import lexer from yaql.language import lexer
from yaql.language.engine import context_aware
from yaql.language.utils import limit from yaql.language.utils import limit
PROMPT = "yaql> " PROMPT = "yaql> "
@ContextAware() @context_aware
@arg('show_tokens')
def main(context, show_tokens): def main(context, show_tokens):
print "Yet Another Query Language - command-line query tool" print "Yet Another Query Language - command-line query tool"
print "Copyright (c) 2013 Mirantis, Inc" print "Copyright (c) 2013 Mirantis, Inc"
@ -49,22 +48,22 @@ def main(context, show_tokens):
if not comm: if not comm:
continue continue
if comm[0] == '@': if comm[0] == '@':
funcName, args = parse_service_command(comm) func_name, args = parse_service_command(comm)
if funcName not in SERVICE_FUNCTIONS: if func_name not in SERVICE_FUNCTIONS:
print "Unknown command " + funcName print "Unknown command " + func_name
else: else:
SERVICE_FUNCTIONS[funcName](args, context) SERVICE_FUNCTIONS[func_name](args, context)
continue continue
try: try:
if show_tokens: if show_tokens:
lexer.input(comm) lexer.lexer.input(comm)
tokens = [] tokens = []
while True: while True:
tok = lexer.token() tok = lexer.lexer.token()
if not tok: if not tok:
break break
tokens.append(tok) tokens.append(tok)
print "Tokens: "+str(tokens) print "Tokens: " + str(tokens)
expr = yaql.parse(comm) expr = yaql.parse(comm)
except YaqlParsingException as ex: except YaqlParsingException as ex:
if ex.position: if ex.position:
@ -103,7 +102,7 @@ def load_data(data_file, context):
def regexp(self, pattern): def regexp(self, pattern):
match = re.match(pattern(), self()) match = re.match(pattern(), self())
if match: if match:
return match.groups() return match.groups()
else: else: