Added --delete and browse

This commit is contained in:
Kevin Veen-Birkenbach 2025-03-21 18:36:00 +01:00
parent 412a7bae16
commit 8cb2f578df
No known key found for this signature in database
GPG Key ID: 44D8F11FD62F878E

36
main.py
View File

@ -177,6 +177,27 @@ def cleanup(args):
command = ["docker", "container", "prune", "-f"] command = ["docker", "container", "prune", "-f"]
run_command(command, args.dry_run) run_command(command, args.dry_run)
def delete_portfolio_container(dry_run=False):
"""
Force remove the portfolio container if it exists.
"""
print("Checking if 'portfolio' container exists to delete...")
command = ["docker", "rm", "-f", "portfolio"]
run_command(command, dry_run)
def browse(args):
"""
Open http://localhost:5000 in Chromium browser.
Command:
chromium http://localhost:5000
This command launches the Chromium browser to view the running application.
"""
command = ["chromium", "http://localhost:5000"]
run_command(command, args.dry_run)
def main(): def main():
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description="CLI tool to manage the Portfolio CMS Docker application." description="CLI tool to manage the Portfolio CMS Docker application."
@ -187,12 +208,24 @@ def main():
help="Print the commands without executing them." help="Print the commands without executing them."
) )
parser.add_argument(
"--delete",
action="store_true",
help="Delete the existing 'portfolio' container before running the command."
)
subparsers = parser.add_subparsers( subparsers = parser.add_subparsers(
title="Commands", title="Commands",
description="Available commands to manage the application", description="Available commands to manage the application",
dest="command" dest="command"
) )
# Browse command
parser_browse = subparsers.add_parser(
"browse", help="Open http://localhost:5000 in Chromium browser."
)
parser_browse.set_defaults(func=browse)
# Build command # Build command
parser_build = subparsers.add_parser( parser_build = subparsers.add_parser(
"build", help="Build the Docker image." "build", help="Build the Docker image."
@ -253,6 +286,9 @@ def main():
parser.print_help() parser.print_help()
sys.exit(1) sys.exit(1)
if args.delete:
delete_portfolio_container(args.dry_run)
# Execute the chosen subcommand function # Execute the chosen subcommand function
args.func(args) args.func(args)