mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-06-26 07:08:06 +02:00
More config cli (#466)
* Extra config CLI tech spec * Describe packaging * Added CLI commands * Add tests
This commit is contained in:
parent
5e71d0cadb
commit
28190fea8a
14 changed files with 1361 additions and 0 deletions
65
trustgraph-cli/trustgraph/cli/list_config_items.py
Normal file
65
trustgraph-cli/trustgraph/cli/list_config_items.py
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
"""
|
||||
Lists configuration items for a specified type
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import json
|
||||
from trustgraph.api import Api
|
||||
|
||||
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
||||
|
||||
def list_config_items(url, config_type, format_type):
|
||||
|
||||
api = Api(url).config()
|
||||
|
||||
keys = api.list(config_type)
|
||||
|
||||
if format_type == "json":
|
||||
print(json.dumps(keys))
|
||||
else:
|
||||
for key in keys:
|
||||
print(key)
|
||||
|
||||
def main():
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
prog='tg-list-config-items',
|
||||
description=__doc__,
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'--type',
|
||||
required=True,
|
||||
help='Configuration type to list',
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'--format',
|
||||
choices=['text', 'json'],
|
||||
default='text',
|
||||
help='Output format (default: text)',
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-u', '--api-url',
|
||||
default=default_url,
|
||||
help=f'API URL (default: {default_url})',
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
|
||||
list_config_items(
|
||||
url=args.api_url,
|
||||
config_type=args.type,
|
||||
format_type=args.format,
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
|
||||
print("Exception:", e, flush=True)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue