cucchiaiata/scripts/cucchiaiata-cli

49 lines
1.4 KiB
Plaintext
Raw Permalink Normal View History

#!/usr/bin/python3
2019-11-29 09:02:10 +01:00
"""Zephir-cmd-input script
"""
2021-05-22 16:39:42 +02:00
from os import environ
2019-12-02 10:30:29 +01:00
from sys import exit, argv
2019-11-29 09:02:10 +01:00
from traceback import print_exc
2021-05-22 16:39:42 +02:00
from json import dumps
2021-04-24 12:57:07 +02:00
from cucchiaiata import Parser, config, Configuration, JsonError
2019-11-29 09:02:10 +01:00
from cucchiaiata.i18n import _
2021-05-22 16:39:42 +02:00
from cucchiaiata.output.interactive import get as interactive_get
from cucchiaiata.output.json import get as json_get
2019-11-29 09:02:10 +01:00
def main():
2021-05-22 16:39:42 +02:00
dico = {'interactive': interactive_get,
'json': json_get,
}
default_outputs = ','.join(dico.keys())
outputs = [dico[output] for output in environ.get('RISOTTO_OUTPUT', default_outputs).split(',')]
2019-11-29 09:02:10 +01:00
try:
2021-04-02 09:16:53 +02:00
if len(argv) > 2 and argv[1] == 'v1.setting.session.configure':
2019-12-02 10:30:29 +01:00
Configuration().get()
else:
parser = Parser()
2021-05-22 16:39:42 +02:00
message = parser.remote_config.option('message').value.get()
for output in outputs:
func = output(message)
if func:
func(parser.get(),
config,
)
break
except KeyboardInterrupt:
pass
2021-04-24 12:57:07 +02:00
except JsonError as err:
print(dumps(err.message,
indent=config.indent),
)
exit(1)
2019-11-29 09:02:10 +01:00
except Exception as err:
if config.debug:
print_exc()
print(_('Error: {}').format(err))
exit(1)
if __name__ == "__main__":
main()