Install Forge commands with custom processing. Extends MarkdownIntegration.setup() to inject Forge-specific transformations after standard template processing.
(
self,
project_root: Path,
manifest: IntegrationManifest,
parsed_options: dict[str, Any] | None = None,
**opts: Any,
)
| 92 | invoke_separator = "-" |
| 93 | |
| 94 | def setup( |
| 95 | self, |
| 96 | project_root: Path, |
| 97 | manifest: IntegrationManifest, |
| 98 | parsed_options: dict[str, Any] | None = None, |
| 99 | **opts: Any, |
| 100 | ) -> list[Path]: |
| 101 | """Install Forge commands with custom processing. |
| 102 | |
| 103 | Extends MarkdownIntegration.setup() to inject Forge-specific transformations |
| 104 | after standard template processing. |
| 105 | """ |
| 106 | templates = self.list_command_templates() |
| 107 | if not templates: |
| 108 | return [] |
| 109 | |
| 110 | project_root_resolved = project_root.resolve() |
| 111 | if manifest.project_root != project_root_resolved: |
| 112 | raise ValueError( |
| 113 | f"manifest.project_root ({manifest.project_root}) does not match " |
| 114 | f"project_root ({project_root_resolved})" |
| 115 | ) |
| 116 | |
| 117 | dest = self.commands_dest(project_root).resolve() |
| 118 | try: |
| 119 | dest.relative_to(project_root_resolved) |
| 120 | except ValueError as exc: |
| 121 | raise ValueError( |
| 122 | f"Integration destination {dest} escapes " |
| 123 | f"project root {project_root_resolved}" |
| 124 | ) from exc |
| 125 | dest.mkdir(parents=True, exist_ok=True) |
| 126 | |
| 127 | script_type = opts.get("script_type", "sh") |
| 128 | arg_placeholder = self.registrar_config.get("args", "{{parameters}}") |
| 129 | created: list[Path] = [] |
| 130 | |
| 131 | for src_file in templates: |
| 132 | raw = src_file.read_text(encoding="utf-8") |
| 133 | # Process template with standard MarkdownIntegration logic |
| 134 | processed = self.process_template( |
| 135 | raw, self.key, script_type, arg_placeholder, |
| 136 | invoke_separator=self.invoke_separator, |
| 137 | project_root=project_root, |
| 138 | ) |
| 139 | |
| 140 | # FORGE-SPECIFIC: Ensure any remaining $ARGUMENTS placeholders are |
| 141 | # converted to {{parameters}} |
| 142 | processed = processed.replace("$ARGUMENTS", arg_placeholder) |
| 143 | |
| 144 | # FORGE-SPECIFIC: Apply frontmatter transformations |
| 145 | processed = self._apply_forge_transformations(processed, src_file.stem) |
| 146 | |
| 147 | dst_name = self.command_filename(src_file.stem) |
| 148 | dst_file = self.write_file_and_record( |
| 149 | processed, dest / dst_name, project_root, manifest |
| 150 | ) |
| 151 | created.append(dst_file) |