-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from nside/spec-cli
Add spec command-line
- Loading branch information
Showing
2 changed files
with
34 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,37 @@ | ||
import argparse | ||
from .app import create_app | ||
from .database import Database | ||
from .openapi import get_openapi_spec | ||
|
||
def main(): | ||
# Create the top-level parser | ||
parser = argparse.ArgumentParser(description='SQLite2REST commands.') | ||
subparsers = parser.add_subparsers(dest='command') | ||
|
||
# Create the parser for the "serve" command | ||
parser_serve = subparsers.add_parser('serve', help='Start a Flask server for an SQLite database.') | ||
parser_serve.add_argument('database', help='The path to the SQLite database.') | ||
|
||
# Create the parser for the "spec" command | ||
parser_spec = subparsers.add_parser('spec', help='Generate OpenAPI spec from SQLite database.') | ||
parser_spec.add_argument('database', help='The path to the SQLite database.') | ||
|
||
# Parse command-line arguments | ||
parser = argparse.ArgumentParser(description='Start a Flask server for an SQLite database.') | ||
parser.add_argument('database', help='The path to the SQLite database.') | ||
args = parser.parse_args() | ||
|
||
# Create the Flask app | ||
app = create_app(args.database) | ||
|
||
# Run the Flask app | ||
app.run() | ||
# Execute the appropriate command | ||
if args.command == 'spec': | ||
# Create the Flask app | ||
app = create_app(args.database) | ||
|
||
# Create an application context | ||
with app.app_context(): | ||
# Generate and print the OpenAPI spec | ||
print(get_openapi_spec(Database(args.database))) | ||
elif args.command == 'serve': | ||
# Create and run the Flask app | ||
app = create_app(args.database) | ||
app.run() | ||
|
||
if __name__ == '__main__': | ||
main() |