Skip to content

Commit 9d49fd3

Browse files
committed
Split output in CLI of single projects using newlines. Fix deserialization of numbers and boolean in CLI.
1 parent 257678a commit 9d49fd3

3 files changed

Lines changed: 29 additions & 7 deletions

File tree

src/finecode/cli.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,10 @@ async def show_user_message(message: str, message_type: str) -> None:
247247
def deserialize_action_payload(raw_payload: dict[str, str]) -> dict[str, typing.Any]:
248248
deserialized_payload = {}
249249
for key, value in raw_payload.items():
250-
if (value.startswith("{") and value.endswith("}")) or (value.startswith('[') and value.endswith(']')):
251-
try:
252-
deserialized_value = json.loads(value)
253-
except json.JSONDecodeError:
254-
deserialized_value = value
255-
else:
250+
try:
251+
# use json deserialize for objects, arrays, numbers, booleans
252+
deserialized_value = json.loads(value)
253+
except json.JSONDecodeError:
256254
deserialized_value = value
257255
deserialized_payload[key] = deserialized_value
258256
return deserialized_payload
@@ -408,7 +406,11 @@ def run(ctx) -> None:
408406
wal_enabled=wal_enabled,
409407
)
410408
)
411-
click.echo(result.output)
409+
410+
# if partial results were printed, final result is empty
411+
if result.output != "":
412+
click.echo(result.output)
413+
412414
if save_results:
413415
results_dir = pathlib.Path(sys.executable).parent.parent / "cache" / "finecode" / "results"
414416
results_dir.mkdir(parents=True, exist_ok=True)

src/finecode/cli_app/commands/run_cmd.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ async def _on_partial_result(params: dict) -> None:
185185
results = value.get("results", {})
186186
streaming_results[project_str] = results
187187
block = _format_project_block(project_str, results, source_to_name)
188+
189+
# split blocks with newline
190+
block = "\n" + block
191+
188192
click.echo(block, nl=False)
189193

190194
client.on_notification("actions/partialResult", _on_partial_result)
@@ -313,6 +317,10 @@ def _format_project_block(
313317

314318
block = "".join(project_output_parts)
315319
block = f"{click.style(project_path_str, bold=True, underline=True)}\n" + block
320+
321+
if not block.endswith("\n"):
322+
block += "\n"
323+
316324
return block
317325

318326

src/finecode/wm_server/runner/runner_client.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@ class RunActionResponse:
6464
return_code: int
6565
status: str = "success"
6666

67+
def json(self) -> dict[str, Any]:
68+
result = self.result_by_format.get("json")
69+
if result is None:
70+
raise ActionRunFailed("Expected json result format but it was not returned")
71+
return result
72+
73+
def text(self) -> str:
74+
result = self.result_by_format.get("styled_text_json") or self.result_by_format.get("string")
75+
if result is None:
76+
raise ActionRunFailed("Expected text result format but it was not returned")
77+
return result
78+
6779

6880
@dataclasses.dataclass
6981
class RunHandlersResponse:

0 commit comments

Comments
 (0)