Skip to content
Snippets Groups Projects
Commit 7d0af930 authored by Lionel Morin's avatar Lionel Morin
Browse files

Add output in yaml

parent 188cee62
No related branches found
No related tags found
1 merge request!10Add output in yaml
Pipeline #190 failed
......@@ -17,10 +17,12 @@ class ZcliConfig:
print("""Attention, le fichier de configuration de zephir-cli est inexistant !""")
url = input("Entrez l'adresse du serveur Zephir : ")
version = input("Entrez la version du zephir (defaut: 'v1') : ")
output = "json"
if not version:
version = "v1"
yaml_template = f"""url: {url}
version: {version}"""
version: {version}
output: {output}"""
with ZcliConfig.config_file.open("w", encoding ="utf-8") as fh:
fh.write(yaml_template)
......@@ -35,3 +37,4 @@ version: {version}"""
self.url = config.get('url')
self.version = config.get('version')
self.output = config.get('output')
#!/usr/bin/env python3
"""Zephir-cmd-input script
"""
import yaml
from zephir_client import remote_json_to_config, cmdline_factory, send
import config as zconf
zcliconf = zconf.ZcliConfig()
URL = zcliconf.url
VERSION = zcliconf.version
OUTPUT = zcliconf.output
remote_config = remote_json_to_config(URL, VERSION)
config = cmdline_factory(remote_config)
......@@ -18,4 +19,8 @@ for key in config.value.mandatory():
config.option(key).value.set(int(text))
else:
config.option(key).value.set(text)
send(URL, VERSION, config)
\ No newline at end of file
result = send(URL, VERSION, config)
if OUTPUT == "yaml":
print(yaml.dump(result, default_flow_style=False))
else:
print(result)
......@@ -59,14 +59,14 @@ def send(url, version, config):
else:
auth_ok = True
if 'error' in response:
print(f"Erreur : {response['error']['kwargs']['reason']}")
return(f"Erreur : {response['error']['kwargs']['reason']}")
else:
print(response)
return(response)
except ValueError:
token = authenticate(url)
continue
except Exception as err:
print(f"Erreur : {err}")
return(f"Erreur : {err}")
sys.exit(1)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment