From 9229e3985344f6fd30707537c282b1b3557fbf5c Mon Sep 17 00:00:00 2001 From: Neeraj Kashyap Date: Wed, 30 Nov 2022 15:04:43 -0800 Subject: [PATCH 1/2] Added "moonstream" CLI with "create-query" command To create queries for Moonstream Query API. --- clients/python/moonstream/cli.py | 56 ++++++++++++++++++++++++++++++++ clients/python/setup.py | 1 + 2 files changed, 57 insertions(+) create mode 100644 clients/python/moonstream/cli.py diff --git a/clients/python/moonstream/cli.py b/clients/python/moonstream/cli.py new file mode 100644 index 000000000..d24a0c185 --- /dev/null +++ b/clients/python/moonstream/cli.py @@ -0,0 +1,56 @@ +import argparse +import textwrap +import uuid + +from .client import Moonstream + + +def handle_create_query(args: argparse.Namespace) -> None: + client = Moonstream() + + query = "" + with args.query_file: + query = textwrap.indent(args.query_file.read(), " ") + + client.create_query(args.token, query, args.name, args.public) + + +def main() -> None: + """ + Execute the Moonstream client command line. + """ + parser = argparse.ArgumentParser( + description="Command-line interface for the Moonstream Python client library. This CLI allows you to use client functionality from your command line." + ) + subparsers = parser.add_subparsers(title="Commands") + + create_query_parser = subparsers.add_parser("create-query") + create_query_parser.add_argument( + "-t", + "--token", + required=True, + type=uuid.UUID, + help="Access token for Moonstream API", + ) + create_query_parser.add_argument( + "--query-file", + required=True, + type=argparse.FileType("r"), + help="File containing the query to add", + ) + create_query_parser.add_argument( + "-n", "--name", required=True, help="Name for the new query" + ) + create_query_parser.add_argument( + "--public", + action="store_true", + help="Set this flag if you want the query to be public", + ) + create_query_parser.set_defaults(func=handle_create_query) + + args = parser.parse_args() + args.func(args) + + +if __name__ == "__main__": + main() diff --git a/clients/python/setup.py b/clients/python/setup.py index a3733873d..8bc5b3494 100644 --- a/clients/python/setup.py +++ b/clients/python/setup.py @@ -36,4 +36,5 @@ "Topic :: Software Development :: Libraries", ], url="https://github.com/bugout-dev/moonstream", + entry_points={"console_scripts": ["moonstream=moonstream.cli:main"]}, ) From b1af1648fcd2be874eec3693e05c3af0a3cfddaf Mon Sep 17 00:00:00 2001 From: Neeraj Kashyap Date: Wed, 30 Nov 2022 15:06:57 -0800 Subject: [PATCH 2/2] Bumped Moonstream client version to 0.1.2 --- clients/python/moonstream/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clients/python/moonstream/version.py b/clients/python/moonstream/version.py index ac0687285..f631c4c50 100644 --- a/clients/python/moonstream/version.py +++ b/clients/python/moonstream/version.py @@ -1 +1 @@ -MOONSTREAM_CLIENT_VERSION = "0.1.1" +MOONSTREAM_CLIENT_VERSION = "0.1.2"