[object Object]

← back to Cli Printing Press

fix(cli): generate correct library install path in READMEs

d9629475f39f8a7f9dfee9931544e02be6caa616 · 2026-04-06 00:17:40 -0700 · Trevin Chow

- Add Category field to APISpec, populated from catalog
- Template now generates install path pointing to the public library repo
  (github.com/mvanhorn/printing-press-library/library/<category>/<cli>)
  instead of a non-existent per-CLI repo
- Fix rewriteModuleInstallPaths regex to handle the library path format
  when publish package rewrites category

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

Files touched

Diff

commit d9629475f39f8a7f9dfee9931544e02be6caa616
Author: Trevin Chow <trevin@trevinchow.com>
Date:   Mon Apr 6 00:17:40 2026 -0700

    fix(cli): generate correct library install path in READMEs
    
    - Add Category field to APISpec, populated from catalog
    - Template now generates install path pointing to the public library repo
      (github.com/mvanhorn/printing-press-library/library/<category>/<cli>)
      instead of a non-existent per-CLI repo
    - Fix rewriteModuleInstallPaths regex to handle the library path format
      when publish package rewrites category
    
    Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---
 internal/cli/root.go                        | 3 +++
 internal/generator/generator_test.go        | 2 +-
 internal/generator/templates/readme.md.tmpl | 4 ++--
 internal/pipeline/modulepath.go             | 2 +-
 internal/spec/spec.go                       | 1 +
 5 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/internal/cli/root.go b/internal/cli/root.go
index 63474be2..b88d2d89 100644
--- a/internal/cli/root.go
+++ b/internal/cli/root.go
@@ -731,4 +731,7 @@ func enrichSpecFromCatalog(apiSpec *spec.APISpec) {
 	if entry.Homepage != "" && apiSpec.WebsiteURL == "" {
 		apiSpec.WebsiteURL = entry.Homepage
 	}
+	if entry.Category != "" && apiSpec.Category == "" {
+		apiSpec.Category = entry.Category
+	}
 }
diff --git a/internal/generator/generator_test.go b/internal/generator/generator_test.go
index 4a464ac4..76e03f23 100644
--- a/internal/generator/generator_test.go
+++ b/internal/generator/generator_test.go
@@ -195,7 +195,7 @@ func TestGenerateWithOwnerField(t *testing.T) {
 	assert.Contains(t, string(mainGo), "testowner")
 	readme, err := os.ReadFile(filepath.Join(outputDir, "README.md"))
 	require.NoError(t, err)
-	assert.Contains(t, string(readme), "go install github.com/testowner/owned-pp-cli/cmd/owned-pp-cli@latest")
+	assert.Contains(t, string(readme), "go install github.com/mvanhorn/printing-press-library/library/other/owned-pp-cli/cmd/owned-pp-cli@latest")
 }
 
 func TestGenerateWithEmptyOwner(t *testing.T) {
diff --git a/internal/generator/templates/readme.md.tmpl b/internal/generator/templates/readme.md.tmpl
index c399389a..4e62904d 100644
--- a/internal/generator/templates/readme.md.tmpl
+++ b/internal/generator/templates/readme.md.tmpl
@@ -9,12 +9,12 @@ Learn more at [{{humanName .Name}}]({{.WebsiteURL}}).{{end}}
 ### Go
 
 ```
-go install github.com/{{.Owner}}/{{.Name}}-pp-cli/cmd/{{.Name}}-pp-cli@latest
+go install github.com/mvanhorn/printing-press-library/library/{{if .Category}}{{.Category}}{{else}}other{{end}}/{{.Name}}-pp-cli/cmd/{{.Name}}-pp-cli@latest
 ```
 
 ### Binary
 
-Download from [Releases](https://github.com/{{.Owner}}/{{.Name}}-pp-cli/releases).
+Download from [Releases](https://github.com/mvanhorn/printing-press-library/releases).
 
 ## Quick Start
 
diff --git a/internal/pipeline/modulepath.go b/internal/pipeline/modulepath.go
index 9d4daa8e..128fd28c 100644
--- a/internal/pipeline/modulepath.go
+++ b/internal/pipeline/modulepath.go
@@ -89,7 +89,7 @@ func hasRewriteExtension(path string) bool {
 }
 
 func rewriteModuleInstallPaths(content, oldPath, newPath string) string {
-	pattern := regexp.MustCompile(`(?:github\.com/[^/\s"]+/)?` + regexp.QuoteMeta(oldPath) + `/cmd/`)
+	pattern := regexp.MustCompile(`(?:\S+/)?` + regexp.QuoteMeta(oldPath) + `/cmd/`)
 	return pattern.ReplaceAllString(content, newPath+"/cmd/")
 }
 
diff --git a/internal/spec/spec.go b/internal/spec/spec.go
index 45f93943..4351be04 100644
--- a/internal/spec/spec.go
+++ b/internal/spec/spec.go
@@ -19,6 +19,7 @@ type APISpec struct {
 	ClientPattern   string              `yaml:"client_pattern,omitempty" json:"client_pattern,omitempty"` // rest (default), proxy-envelope — affects generated HTTP client
 	ProxyRoutes     map[string]string   `yaml:"proxy_routes,omitempty" json:"proxy_routes,omitempty"`     // path prefix → service name for proxy-envelope routing
 	WebsiteURL      string              `yaml:"website_url,omitempty" json:"website_url,omitempty"`       // product/company website (not the API base URL)
+	Category        string              `yaml:"category,omitempty" json:"category,omitempty"`             // catalog category (e.g., productivity, developer-tools) — used for library install path
 	Auth            AuthConfig          `yaml:"auth" json:"auth"`
 	RequiredHeaders []RequiredHeader    `yaml:"required_headers,omitempty" json:"required_headers,omitempty"`
 	Config          ConfigSpec          `yaml:"config" json:"config"`

← 1b4b9844 feat(cli): rename What's New Here to Unique Features, move a  ·  back to Cli Printing Press  ·  chore(main): release 1.1.0 (#134) 0e30fc53 →