Skip to content
Snippets Groups Projects
Commit 20c60a1a authored by Bruno Boiget's avatar Bruno Boiget Committed by Matthieu Lamalle
Browse files

Add describe command to client

parent aa1967ac
No related branches found
No related tags found
No related merge requests found
......@@ -5,7 +5,7 @@ import yaml
import sys
from json import dumps
from pathlib import Path
from zephir_client import remote_json_to_config, cmdline_factory, send, remove_token, list_messages, authenticate
from zephir_client import remote_json_to_config, cmdline_factory, send, remove_token, list_messages, describe_messages, authenticate
import config as zconf
# get calling script base name
......@@ -16,7 +16,7 @@ def main():
URL = zcliconf.url
VERSION = zcliconf.version
OUTPUT = 'yaml'
list_msgs = False
list_msgs = 0
prettyjson = 2
if '--json' in sys.argv:
......@@ -54,22 +54,38 @@ def main():
if 'list' in sys.argv:
if '-h' in sys.argv or '--help' in sys.argv:
help()
list_msgs = True
list_msgs = 1
start = None
if len(sys.argv) > 2 :
start = sys.argv[2]
sys.argv.remove(start)
sys.argv.remove('list')
if 'describe' in sys.argv:
if '-h' in sys.argv or '--help' in sys.argv:
help()
list_msgs = 2
start = None
if len(sys.argv) > 2 :
start = sys.argv[2]
sys.argv.remove(start)
sys.argv.remove('describe')
remote_config = remote_json_to_config(URL, VERSION)
config = cmdline_factory(remote_config)
if list_msgs:
messages = list_messages(config, start)
if list_msgs == 1:
messages = list_messages(config, start)
elif list_msgs == 2:
messages = describe_messages(config, start)
if not messages:
print("Aucun résultat.")
elif OUTPUT == "yaml":
print("\n{}".format(yaml.dump(messages, default_flow_style=False)))
print("\n")
for msg in messages:
print(msg)
print("\n")
else:
print(dumps(messages, indent=prettyjson ))
sys.exit(0)
......@@ -113,6 +129,9 @@ Client pour interroger un serveur Zéphir.
{progname} list [recherche]
Liste les commandes disponibles commençant par <recherche>.
{progname} describe [recherche]
Décrit les commandes disponibles commençant par <recherche>.
{progname} commande [paramètres]
Exécute le message avec ses paramètres.
......
......@@ -43,6 +43,23 @@ def list_messages(config, start=None):
else:
return messages
def describe_messages(config, start=None):
"""Describes all available messages from config
"""
messages = config.option('message').value.list()
descr = []
for msg in messages:
# activate each message to enable matching options
config.option('message').value.set(msg)
# retrieve message doc in matching optiondescription
try:
doc = list(config.option.list(type='all'))[1].option.doc()
except:
doc = '!No description available!'
if start is None or msg.startswith(start):
descr.append(f"{msg}\n {doc}")
return descr
def send(url, version, config):
# check authentication
# retrieve new message value
......
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