Skip to content

Commit

Permalink
Add CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
tombaeyens committed Jan 30, 2025
1 parent 865e4ae commit f54a0b9
Showing 2 changed files with 75 additions and 0 deletions.
5 changes: 5 additions & 0 deletions soda-core/setup.py
Original file line number Diff line number Diff line change
@@ -37,4 +37,9 @@
"Operating System :: POSIX :: Linux",
"Programming Language :: Python :: 3.10",
],
entry_points={
"console_scripts": [
"soda=soda_core.cli.soda:main",
]
}
)
70 changes: 70 additions & 0 deletions soda-core/src/soda_core/cli/soda.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import argparse
from textwrap import dedent


def verify_contract(contract_file_path: str):
print(f"verifying contract {contract_file_path}")


def main():
print(dedent("""
__| _ \ _ \ \\
\__ \ ( || | _ \\
____/\___/___/_/ _\\ 4.0.0b1
"""))

cli_parser = argparse.ArgumentParser(
description="The Soda CLI"
)

sub_parsers = cli_parser.add_subparsers(dest="command", help='Subcommand description')
parser = sub_parsers.add_parser('verify', help='Verify a contract')

parser.add_argument(
"-c", "--contract",
type=str,
help="A contract file path. Prepend -c for each contract file you specify."
)
parser.add_argument(
"-s", "--send-results",
const=True,
action='store_const',
help="Sends contract verification results to Soda Cloud."
)
parser.add_argument(
"-a", "--use-agent",
const=True,
action='store_const',
help="Executes contract verification on Soda Agent instead of locally in this library."
)
parser.add_argument(
"-sp", "--skip-publish",
const=True,
action='store_const',
help="Skips publishing of the contract when sending results to Soda Cloud. Precondition: The contract version "
"must already exist on Soda Cloud."
)

parser = sub_parsers.add_parser('publish', help='Publish a contract')
parser.add_argument(
"-c", "--contract",
type=str,
help="A contract file path. Prepend -c for each contract file you specify."
)

parser = sub_parsers.add_parser('help', help='Soda CLI help')

args = cli_parser.parse_args()

try:
if args.command == "verify":
verify_contract(args.contract)
else:
cli_parser.print_help()
except Exception as e:
cli_parser.print_help()
print(f"Error: {e}")


if __name__ == "__main__":
main()

0 comments on commit f54a0b9

Please sign in to comment.