@@ -125,8 +125,9 @@ def run(cli_ctx, account, runner_class, recorder_class, max_exceptions, path, bo
125
125
126
126
127
127
@cli .command (cls = ConnectedProviderCommand , section = "Local Commands" )
128
+ @click .option ("--generate" , is_flag = True , default = False )
128
129
@click .argument ("path" , required = False , type = str , default = "bots" )
129
- def build (path ):
130
+ def build (generate , path ):
130
131
"""Auto-generate Dockerfiles"""
131
132
if not (path := Path .cwd () / path ).exists ():
132
133
raise FileNotFoundError (
@@ -135,25 +136,23 @@ def build(path):
135
136
)
136
137
files = {file for file in path .iterdir () if file .is_file ()}
137
138
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 } " )
157
156
158
157
159
158
@cli .command (cls = ConnectedProviderCommand , section = "Local Commands" )
0 commit comments