Install commands to the user-provided commands directory.
(
self,
project_root: Path,
manifest: IntegrationManifest,
parsed_options: dict[str, Any] | None = None,
**opts: Any,
)
| 85 | ) |
| 86 | |
| 87 | def setup( |
| 88 | self, |
| 89 | project_root: Path, |
| 90 | manifest: IntegrationManifest, |
| 91 | parsed_options: dict[str, Any] | None = None, |
| 92 | **opts: Any, |
| 93 | ) -> list[Path]: |
| 94 | """Install commands to the user-provided commands directory.""" |
| 95 | commands_dir = self._resolve_commands_dir(parsed_options, opts) |
| 96 | |
| 97 | templates = self.list_command_templates() |
| 98 | if not templates: |
| 99 | return [] |
| 100 | |
| 101 | project_root_resolved = project_root.resolve() |
| 102 | if manifest.project_root != project_root_resolved: |
| 103 | raise ValueError( |
| 104 | f"manifest.project_root ({manifest.project_root}) does not match " |
| 105 | f"project_root ({project_root_resolved})" |
| 106 | ) |
| 107 | |
| 108 | dest = (project_root / commands_dir).resolve() |
| 109 | try: |
| 110 | dest.relative_to(project_root_resolved) |
| 111 | except ValueError as exc: |
| 112 | raise ValueError( |
| 113 | f"Integration destination {dest} escapes " |
| 114 | f"project root {project_root_resolved}" |
| 115 | ) from exc |
| 116 | dest.mkdir(parents=True, exist_ok=True) |
| 117 | |
| 118 | script_type = opts.get("script_type", "sh") |
| 119 | arg_placeholder = "$ARGUMENTS" |
| 120 | created: list[Path] = [] |
| 121 | |
| 122 | for src_file in templates: |
| 123 | raw = src_file.read_text(encoding="utf-8") |
| 124 | processed = self.process_template( |
| 125 | raw, self.key, script_type, arg_placeholder, |
| 126 | project_root=project_root, |
| 127 | ) |
| 128 | dst_name = self.command_filename(src_file.stem) |
| 129 | dst_file = self.write_file_and_record( |
| 130 | processed, dest / dst_name, project_root, manifest |
| 131 | ) |
| 132 | created.append(dst_file) |
| 133 | |
| 134 | |
| 135 | return created |
nothing calls this directly
no test coverage detected