Skip to content

Commit be17bfd

Browse files
committed
Adding delete_project CLI helper.
1 parent 7c90947 commit be17bfd

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

cli/delete_project.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env python3
2+
# coding=utf-8
3+
# PYTHON_ARGCOMPLETE_OK
4+
5+
import sys
6+
from argparse import ArgumentParser
7+
8+
# Allow this script to be used from the parent directory
9+
sys.path.append(".")
10+
11+
from app import db
12+
from app.models import Project
13+
14+
15+
def main():
16+
# Parse arguments
17+
argument_parser = ArgumentParser(description="Delete a project.")
18+
argument_parser.add_argument(
19+
"--project", type=str, required=True,
20+
help="The name of the project to delete."
21+
)
22+
arguments = argument_parser.parse_args()
23+
24+
# Find that project
25+
project_query = Project.query.filter(Project.name == arguments.project)
26+
if project_query.count() == 0:
27+
print(f"Project '{arguments.project}' does not exist", file=sys.stderr)
28+
exit(1)
29+
30+
# Delete the project from the DB
31+
db.session.delete(project_query.first())
32+
db.session.commit()
33+
34+
print(f"Project '{arguments.project}' deleted successfully.")
35+
exit(0)
36+
37+
38+
if __name__ == "__main__":
39+
main()

0 commit comments

Comments
 (0)