Skip to content

Commit b7fb968

Browse files
committed
feat: add generate flag
1 parent 27e54cd commit b7fb968

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

silverback/_cli.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,9 @@ def run(cli_ctx, account, runner_class, recorder_class, max_exceptions, path, bo
125125

126126

127127
@cli.command(cls=ConnectedProviderCommand, section="Local Commands")
128+
@click.option("--generate", is_flag=True, default=False)
128129
@click.argument("path", required=False, type=str, default="bots")
129-
def build(path):
130+
def build(generate, path):
130131
"""Auto-generate Dockerfiles"""
131132
if not (path := Path.cwd() / path).exists():
132133
raise FileNotFoundError(
@@ -135,25 +136,23 @@ def build(path):
135136
)
136137
files = {file for file in path.iterdir() if file.is_file()}
137138
bots = []
138-
for file in files:
139-
if "__init__" in file.name:
140-
if not click.confirm(
141-
"There is an __init__.py file in the bots directory,\n"
142-
f"making the {path}/ directory a python package.\n"
143-
"Are you sure you want to generate a Dockerfile for all "
144-
"files in this directory?"
145-
):
146-
return
147-
continue
148-
bots.append(file)
149-
for bot in bots:
150-
docker_filename = f"Dockerfile.{bot.name.replace('.py', '')}"
151-
dockerfile_content = DOCKERFILE_CONTENT
152-
dockerfile_content += f"COPY {path.name}/{bot.name} bots/bot.py"
153-
dockerfile_path = Path.cwd() / ".silverback-images" / docker_filename
154-
dockerfile_path.parent.mkdir(exist_ok=True)
155-
dockerfile_path.write_text(dockerfile_content.strip() + "\n")
156-
click.echo(f"Generated {dockerfile_path}")
139+
if generate:
140+
for file in files:
141+
if "__init__" in file.name:
142+
bots = [file]
143+
break
144+
bots.append(file)
145+
for bot in bots:
146+
if '__init__' in bot.name:
147+
docker_filename = f"Dockerfile.{bot.parent.name}"
148+
else:
149+
docker_filename = f"Dockerfile.{bot.name.replace('.py', '')}"
150+
dockerfile_content = DOCKERFILE_CONTENT
151+
dockerfile_content += f"COPY {path.name}/{bot.name} bots/bot.py"
152+
dockerfile_path = Path.cwd() / ".silverback-images" / docker_filename
153+
dockerfile_path.parent.mkdir(exist_ok=True)
154+
dockerfile_path.write_text(dockerfile_content.strip() + "\n")
155+
click.echo(f"Generated {dockerfile_path}")
157156

158157

159158
@cli.command(cls=ConnectedProviderCommand, section="Local Commands")

0 commit comments

Comments
 (0)