Skip to content

Commit dff9a0e

Browse files
committed
no positional args in dev
1 parent b168027 commit dff9a0e

File tree

3 files changed

+46
-29
lines changed

3 files changed

+46
-29
lines changed

src/epics_containers_cli/dev/dev_cli.py

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,13 @@ def launch_local(
5757
IOC project folder.
5858
"""
5959
DevCommands().launch_local(
60-
ioc_instance, generic_ioc, execute, target, tag, args, ioc_name
60+
ioc_instance=ioc_instance,
61+
generic_ioc=generic_ioc,
62+
execute=execute,
63+
target=target,
64+
tag=tag,
65+
args=args,
66+
ioc_name=ioc_name,
6167
)
6268

6369

@@ -93,7 +99,15 @@ def launch(
9399
instances. You may find the devcontainer a more convenient way to
94100
do this.
95101
"""
96-
DevCommands().launch(ioc_instance, execute, target, image, tag, args, ioc_name)
102+
DevCommands().launch(
103+
ioc_instance=ioc_instance,
104+
execute=execute,
105+
target=target,
106+
image=image,
107+
tag=tag,
108+
args=args,
109+
ioc_name=ioc_name,
110+
)
97111

98112

99113
@dev.command()
@@ -110,7 +124,7 @@ def debug_last(
110124
Useful for debugging failed builds - if the last build failed it will
111125
start the container after the most recent successful build step.
112126
"""
113-
DevCommands().debug_last(generic_ioc, mount_repos)
127+
DevCommands().debug_last(generic_ioc=generic_ioc, mount_repos=mount_repos)
114128

115129

116130
@dev.command()
@@ -133,7 +147,7 @@ def versions(
133147
or the local project folder (defaults to .) e.g.
134148
ec dev versions ../ioc-template
135149
"""
136-
DevCommands().versions(generic_ioc, arch, image)
150+
DevCommands().versions(generic_ioc=generic_ioc, arch=arch, image=image)
137151

138152

139153
@dev.command()
@@ -146,24 +160,24 @@ def stop(
146160
"""
147161
Stop a running local IOC container
148162
"""
149-
DevCommands().stop(ioc_name)
163+
DevCommands().stop(ioc_name=ioc_name)
150164

151165

152166
@dev.command()
153167
def exec(
154168
ctx: typer.Context,
155-
ioc_name: str = typer.Option(
156-
IOC_NAME, help="container name override. Use to run multiple instances"
157-
),
158169
command: str = typer.Argument(
159170
"bash", help="command to execute inside the container must be 'single quoted'"
160171
),
172+
ioc_name: str = typer.Option(
173+
IOC_NAME, help="container name override. Use to run multiple instances"
174+
),
161175
args: str = typer.Option("", help="Additional args for exec, 'must be quoted'"),
162176
):
163177
"""
164178
Execute a command inside a running local IOC container
165179
"""
166-
DevCommands().exec(ioc_name, command, args)
180+
DevCommands().exec(ioc_name=ioc_name, command=command, args=args)
167181

168182

169183
@dev.command()
@@ -180,7 +194,7 @@ def wait_pv(
180194
"""
181195
Execute a command inside a running local IOC container
182196
"""
183-
DevCommands().wait_pv(pv_name, ioc_name, attempts)
197+
DevCommands().wait_pv(pv_name=pv_name, ioc_name=ioc_name, attempts=attempts)
184198

185199

186200
@dev.command()
@@ -206,13 +220,13 @@ def build(
206220
Builds both developer and runtime targets.
207221
"""
208222
DevCommands().build(
209-
generic_ioc,
210-
tag,
211-
arch,
212-
platform,
213-
cache,
214-
cache_from,
215-
cache_to,
216-
push,
217-
rebuild,
223+
generic_ioc=generic_ioc,
224+
tag=tag,
225+
arch=arch,
226+
platform=platform,
227+
cache=cache,
228+
cache_from=cache_from,
229+
cache_to=cache_to,
230+
push=push,
231+
rebuild=rebuild,
218232
)

src/epics_containers_cli/dev/dev_commands.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import time
22
from pathlib import Path
3-
from subprocess import CalledProcessError
43
from typing import Optional
54

65
import typer
@@ -158,23 +157,21 @@ def stop(self, ioc_name: str):
158157
"""
159158
self.docker.stop(ioc_name)
160159

161-
def exec(self, command: str, ioc_name: str, args: str = ""):
160+
def exec(self, ioc_name: str, command: str, args: str = ""):
162161
"""
163162
execute a command in a locally running container
164163
"""
165-
self.docker.exec(command, ioc_name, args)
164+
self.docker.exec(container=ioc_name, command=command, args=args)
166165

167166
def wait_pv(self, pv_name: str, ioc_name: str, attempts: int):
168167
"""
169168
wait for a local IOC instance to start by monitoring for a PV
170169
"""
171170
for i in range(attempts):
172-
try:
173-
cmd = f"caget {pv_name}"
174-
result = self.docker.exec(ioc_name, cmd, interactive=False)
175-
except CalledProcessError:
176-
pass # assume the IOC is not running yet
177-
171+
cmd = f"caget {pv_name}"
172+
result = self.docker.exec(
173+
container=ioc_name, command=cmd, interactive=False, errorOK=True
174+
)
178175
if str(result).startswith(pv_name):
179176
break
180177
time.sleep(1)

src/epics_containers_cli/docker.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,12 @@ def build(
133133
run_command(f"{cmd} build --target {target}{t_arch} {args} -t {name} {context}")
134134

135135
def exec(
136-
self, container: str, command: str, args: str = "", interactive: bool = True
136+
self,
137+
container: str,
138+
command: str,
139+
args: str = "",
140+
interactive: bool = True,
141+
errorOK: bool = False,
137142
):
138143
"""
139144
execute a command in a local IOC instance
@@ -143,6 +148,7 @@ def exec(
143148
result = run_command(
144149
f'{self.docker} exec {args}{container} bash -c "{command}"',
145150
interactive=interactive,
151+
error_OK=errorOK,
146152
)
147153
return result
148154

0 commit comments

Comments
 (0)