演示参数化
(tmpDir string)
| 196 | |
| 197 | // 演示参数化 |
| 198 | func demonstrateParameters(tmpDir string) { |
| 199 | fmt.Println("\n📋 参数化 Recipe") |
| 200 | fmt.Println(repeatStr("-", 50)) |
| 201 | |
| 202 | yamlContent := ` |
| 203 | version: "1.0" |
| 204 | title: Project Generator |
| 205 | description: 生成项目模板的 AI 助手 |
| 206 | |
| 207 | parameters: |
| 208 | - key: project_name |
| 209 | input_type: string |
| 210 | requirement: required |
| 211 | description: 项目名称 |
| 212 | default: my-project |
| 213 | |
| 214 | - key: language |
| 215 | input_type: select |
| 216 | requirement: required |
| 217 | description: 编程语言 |
| 218 | default: go |
| 219 | options: |
| 220 | - go |
| 221 | - python |
| 222 | - typescript |
| 223 | - rust |
| 224 | |
| 225 | - key: with_tests |
| 226 | input_type: boolean |
| 227 | requirement: optional |
| 228 | description: 是否包含测试模板 |
| 229 | default: "true" |
| 230 | |
| 231 | - key: license |
| 232 | input_type: select |
| 233 | requirement: optional |
| 234 | description: 开源许可证 |
| 235 | options: |
| 236 | - MIT |
| 237 | - Apache-2.0 |
| 238 | - GPL-3.0 |
| 239 | |
| 240 | prompt: | |
| 241 | 请为我创建一个名为 {{project_name}} 的 {{language}} 项目。 |
| 242 | {{#if with_tests}}包含测试模板。{{/if}} |
| 243 | {{#if license}}使用 {{license}} 许可证。{{/if}} |
| 244 | |
| 245 | tools: |
| 246 | - Write |
| 247 | - Bash |
| 248 | ` |
| 249 | |
| 250 | yamlPath := filepath.Join(tmpDir, "project-generator.yaml") |
| 251 | if err := os.WriteFile(yamlPath, []byte(yamlContent), 0644); err != nil { |
| 252 | log.Fatalf("写入 YAML 失败: %v", err) |
| 253 | } |
| 254 | |
| 255 | r, err := recipe.LoadFromFile(yamlPath) |
no test coverage detected