|
110 | 110 | from fixcore.db.model import QueryModel |
111 | 111 | from fixcore.db.runningtaskdb import RunningTaskData |
112 | 112 | from fixcore.error import CLIParseError, ClientError, CLIExecutionError, NotEnoughPermissions |
113 | | -from fixcore.ids import ConfigId, TaskId, InfraAppName, TaskDescriptorId, GraphName, Email, Password |
| 113 | +from fixcore.ids import ConfigId, TaskId, InfraAppName, TaskDescriptorId, GraphName, Email, Password, NodeId |
114 | 114 | from fixcore.infra_apps.manifest import AppManifest |
115 | 115 | from fixcore.infra_apps.package_manager import Failure |
116 | 116 | from fixcore.model.graph_access import Section, EdgeTypes |
@@ -6553,6 +6553,46 @@ async def process_element(el: JsonElement) -> JsonElement: |
6553 | 6553 | return CLIFlow(setup_stream, required_permissions={Permission.read}) |
6554 | 6554 |
|
6555 | 6555 |
|
| 6556 | +class NodeCommand(CLICommand): |
| 6557 | + """ |
| 6558 | + node delete <node_id> |
| 6559 | + """ |
| 6560 | + |
| 6561 | + @property |
| 6562 | + def name(self) -> str: |
| 6563 | + return "node" |
| 6564 | + |
| 6565 | + def args_info(self) -> ArgsInfo: |
| 6566 | + return { |
| 6567 | + "delete": [ |
| 6568 | + ArgInfo("--keep-history", False, help_text=""), |
| 6569 | + ArgInfo(None, True, help_text="<node_id>"), |
| 6570 | + ] |
| 6571 | + } |
| 6572 | + |
| 6573 | + def info(self) -> str: |
| 6574 | + return "Operations on nodes" |
| 6575 | + |
| 6576 | + def parse(self, arg: Optional[str] = None, ctx: CLIContext = EmptyContext, **kwargs: Any) -> CLIAction: |
| 6577 | + async def delete_node(node_id: NodeId, keep_history: bool) -> AsyncIterator[str]: |
| 6578 | + model = await self.dependencies.model_handler.load_model(ctx.graph_name) |
| 6579 | + await self.dependencies.db_access.get_graph_db(ctx.graph_name).delete_node(node_id, model, keep_history) |
| 6580 | + yield f"Node {node_id} deleted." |
| 6581 | + |
| 6582 | + if arg: |
| 6583 | + args = arg.split(maxsplit=1) |
| 6584 | + if len(args) == 2 and args[0] == "delete": |
| 6585 | + parser = NoExitArgumentParser() |
| 6586 | + parser.add_argument("node_id", type=str) |
| 6587 | + parser.add_argument("--keep-history", action="store_true") |
| 6588 | + parsed = parser.parse_args(args_parts_unquoted_parser.parse(args[1])) |
| 6589 | + return CLISource.single( |
| 6590 | + fn=partial(delete_node, node_id=parsed.node_id, keep_history=parsed.keep_history), |
| 6591 | + required_permissions={Permission.write}, |
| 6592 | + ) |
| 6593 | + return CLISource.single(lambda: stream.just(self.rendered_help(ctx)), required_permissions={Permission.read}) |
| 6594 | + |
| 6595 | + |
6556 | 6596 | def all_commands(d: TenantDependencies) -> List[CLICommand]: |
6557 | 6597 | commands = [ |
6558 | 6598 | AggregateCommand(d, "search"), |
@@ -6582,6 +6622,7 @@ def all_commands(d: TenantDependencies) -> List[CLICommand]: |
6582 | 6622 | KindsCommand(d, "search", allowed_in_source_position=True), |
6583 | 6623 | LimitPart(d, "search"), |
6584 | 6624 | ListCommand(d, "format"), |
| 6625 | + NodeCommand(d, "action", allowed_in_source_position=True), |
6585 | 6626 | TemplatesCommand(d, "search", allowed_in_source_position=True), |
6586 | 6627 | PredecessorsPart(d, "search"), |
6587 | 6628 | ProtectCommand(d, "action"), |
|
0 commit comments