Skip to content

Commit 61686a2

Browse files
olehermanseclaude
andcommitted
cfengine build: Stopped prompting to deploy if not possible
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com> Signed-off-by: Ole Herman Schumacher Elgesem <ole@northern.tech>
1 parent 7b9a79b commit 61686a2

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

‎src/cfengine_cli/cfengine_wrapper/cfengine_commands.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
)
3232
from cfengine_cli.cfengine_wrapper.cfengine_utils import (
3333
extract_agent_file,
34+
has_known_hubs,
3435
prompt_two_options,
3536
prompt_yes_no,
3637
require_executable,
@@ -249,6 +250,10 @@ def build(hub=None, non_interactive=False) -> int:
249250
rc = build_command()
250251
if rc != 0:
251252
return rc
253+
if not hub and not has_known_hubs():
254+
# Nothing to deploy to, so don't ask. Mirrors the check cf-remote's
255+
# deploy does (it errors with "No hub to deploy to" in this case).
256+
return 0
252257
if prompt_yes_no(
253258
"Deploy the built policy set now?",
254259
default=True,

‎src/cfengine_cli/cfengine_wrapper/cfengine_utils.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ def _known_hosts(role_filter=None) -> Iterator[tuple[str, list[str]]]:
9090
yield host_id, aliases
9191

9292

93+
def has_known_hubs() -> bool:
94+
"""True if cf-remote knows about any saved/spawned hub (without connecting)."""
95+
return any(True for _ in _known_hosts("hub"))
96+
97+
9398
@lru_cache(maxsize=None)
9499
def _host_info(host: str):
95100
try:

0 commit comments

Comments
 (0)