diff --git a/fixcore/fixcore/cli/command.py b/fixcore/fixcore/cli/command.py index 13c8e8a0ec..2df50e7b74 100644 --- a/fixcore/fixcore/cli/command.py +++ b/fixcore/fixcore/cli/command.py @@ -3834,9 +3834,9 @@ def args_info(self) -> ArgsInfo: return [ArgInfo(expects_value=True, value_hint="file", help_text="file to write to")] @staticmethod - async def write_result_to_file(in_stream: JsStream, file_name: str) -> AsyncIterator[JsonElement]: + async def write_result_to_file(ctx: CLIContext, in_stream: JsStream, file_name: str) -> AsyncIterator[JsonElement]: async with TemporaryDirectory() as temp_dir: - path = os.path.join(temp_dir, uuid_str()) + path = file_name if ctx.intern else os.path.join(temp_dir, uuid_str()) async with aiofiles.open(path, "w") as f: async with in_stream.stream() as streamer: async for out in streamer: @@ -3858,7 +3858,7 @@ def parse(self, arg: Optional[str] = None, ctx: CLIContext = EmptyContext, **kwa if (ex := self.get_previous_command(kwargs)) and ex.action.produces == MediaType.FilePath: fn = self.already_file_stream else: - fn = self.write_result_to_file + fn = partial(self.write_result_to_file, ctx) return CLIFlow(lambda in_stream: fn(in_stream, arg), MediaType.FilePath, required_permissions={Permission.read}) diff --git a/fixcore/fixcore/cli/model.py b/fixcore/fixcore/cli/model.py index b7fcb24c3e..04cb020e0d 100644 --- a/fixcore/fixcore/cli/model.py +++ b/fixcore/fixcore/cli/model.py @@ -119,6 +119,11 @@ def graph_name(self) -> GraphName: def section(self) -> str: return self.env.get("section", PathRoot) + @property + def intern(self) -> bool: + # currently only 2 sources: api and task_handler + return self.source == "task_handler" + @property def user_permissions(self) -> Set[Permission]: return self.user.permissions if self.user else set()