Skip to content

Commit 20f439a

Browse files
made changes to file structures and made docker a sub-group of cli main group.
1 parent 9953156 commit 20f439a

File tree

3 files changed

+60
-16
lines changed

3 files changed

+60
-16
lines changed

commands/docker/__init__.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import os
2+
3+
def get_python_modules(path):
4+
"""
5+
Recursively get a list of valid Python files to import as modules.
6+
"""
7+
module_list = []
8+
for root, dirs, files in os.walk(path):
9+
for file in files:
10+
if not file.startswith('-') and not file.startswith('.') and file.endswith('.py'):
11+
# Exclude files starting with '-' and '.'
12+
# Include only Python files ending with '.py'
13+
file_path = os.path.join(root, file)
14+
if os.path.isfile(file_path):
15+
# If it's a file, add it to the module list without the '.py' extension
16+
module_list.append(os.path.splitext(os.path.relpath(file_path, start=path))[0].replace(os.sep, '.'))
17+
return module_list
18+
19+
# Get the directory where this __init__.py is located
20+
directory = os.path.dirname(__file__)
21+
22+
# Get the list of Python modules in the current directory and subdirectories
23+
module_list = get_python_modules(directory)
24+
25+
# Use the generated module list for wildcard imports
26+
__all__ = module_list
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def docker_connection_checker():
7171
@click.option("--verbose", is_flag=True, help="Enable verbose output.")
7272
@click.option("--log-level", type=click.Choice(["DEBUG", "INFO", "WARNING", "ERROR"], case_sensitive=False),
7373
default="INFO", help="Set the logging level.")
74-
def docker_cleanup(verbose, log_level):
74+
def cleanup(verbose, log_level):
7575
log_level = getattr(logging, log_level.upper(), logging.INFO)
7676
logger.setLevel(log_level)
7777
if verbose:
@@ -180,13 +180,13 @@ def prune_all(dry_run, force):
180180

181181
# =============== ADDING COMMANDS TO GROUPS
182182

183-
docker_cleanup.add_command(prune_containers)
184-
docker_cleanup.add_command(prune_images)
185-
docker_cleanup.add_command(prune_volumes)
186-
docker_cleanup.add_command(prune_networks)
187-
docker_cleanup.add_command(prune_all)
183+
cleanup.add_command(prune_containers)
184+
cleanup.add_command(prune_images)
185+
cleanup.add_command(prune_volumes)
186+
cleanup.add_command(prune_networks)
187+
cleanup.add_command(prune_all)
188188

189189
# =============== SCRIPT ENTRYPOINT
190190

191191
if __name__ == "__main__":
192-
docker_cleanup()
192+
cleanup()

dev_cli/dev_cli.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,45 @@
55
import sys
66
from pathlib import Path
77

8-
# get current script directory
8+
# =============== PATH SETUP
9+
910
currentdir = Path(__file__).resolve().parent
10-
# get parent directory
1111
parentdir = currentdir.parent
1212
# add parent directory to sys.path
1313
sys.path.insert(0, str(parentdir))
1414

15-
# import modules from commands.personal directory
16-
from commands import docker_cleanup
15+
# =============== IMPORTING DOCKER MODULES
16+
17+
# import modules from commands.docker
18+
from commands.docker import cleanup
19+
20+
# =============== CLI GROUP
1721

18-
# define main command group for the CLI Tool
22+
# define main command group for the cli tool
1923
@click.group(help="dev-cli tool: a command-line interface for various devops utilities.")
2024
def cli():
2125
"""Main entry point for dev-cli Tool."""
22-
# function doesn't do anything.
23-
# is REQUIRED for defining the command group
26+
# function doesn't do anything.
27+
# is REQUIRED for defining the command group
2428
pass
2529

26-
cli.add_command(docker_cleanup.docker_cleanup)
30+
# =============== DOCKER SUB-GROUP
31+
32+
# define docker command group
33+
@click.group(help="Commands for automating docker operations.")
34+
def docker():
35+
pass
36+
37+
# add commands to docker group
38+
docker.add_command(cleanup.cleanup)
39+
40+
# =============== ADD SUB-GROUPS TO MAIN CLI GROUP
41+
42+
# add docker group to the main cli group
43+
cli.add_command(docker)
44+
45+
# =============== SCRIPT ENTRYPOINT
2746

28-
# entry point of the script.
2947
# calls the cli tool if the script is executed.
3048
if __name__ == "__main__":
3149
cli()

0 commit comments

Comments
 (0)