← back to Cli Printing Press
feat(generator): Apache 2.0 license on generated CLIs with NOTICE attribution
86c5d908f7ffe8c8b7a3e015766b1b85fec0cebb · 2026-03-26 11:45:21 -0700 · Matt Van Horn
The printing press itself stays MIT. Every CLI it generates ships with:
- Apache 2.0 LICENSE file (patent grant + NOTICE preservation requirement)
- NOTICE file crediting CLI Printing Press and Matt Van Horn
- Apache 2.0 SPDX header on every generated .go file:
"Copyright {year} {owner}. Licensed under Apache-2.0. See LICENSE."
"Generated by CLI Printing Press (github.com/mvanhorn/cli-printing-press)"
Companies that ship CLIs generated by the press must preserve the NOTICE
file in their distribution. This is the standard approach used by protoc,
OpenAPI Generator, and Swagger Codegen.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Files touched
M internal/generator/generator.goM internal/generator/generator_test.goA internal/generator/templates/LICENSE.tmplA internal/generator/templates/NOTICE.tmplM internal/generator/templates/analytics.go.tmplM internal/generator/templates/auth.go.tmplA internal/generator/templates/auth_simple.go.tmplA internal/generator/templates/cache.go.tmplM internal/generator/templates/channel_workflow.go.tmplM internal/generator/templates/client.go.tmplM internal/generator/templates/command.go.tmplA internal/generator/templates/command_endpoint.go.tmplA internal/generator/templates/command_parent.go.tmplM internal/generator/templates/config.go.tmplM internal/generator/templates/doctor.go.tmplM internal/generator/templates/export.go.tmplM internal/generator/templates/helpers.go.tmplM internal/generator/templates/import.go.tmplM internal/generator/templates/insights/health_score.go.tmplM internal/generator/templates/insights/similar.go.tmplM internal/generator/templates/main.go.tmplM internal/generator/templates/root.go.tmplM internal/generator/templates/search.go.tmplM internal/generator/templates/store.go.tmplM internal/generator/templates/sync.go.tmplM internal/generator/templates/tail.go.tmplM internal/generator/templates/types.go.tmplM internal/generator/templates/workflows/pm_load.go.tmplM internal/generator/templates/workflows/pm_orphans.go.tmplM internal/generator/templates/workflows/pm_stale.go.tmpl
Diff
commit 86c5d908f7ffe8c8b7a3e015766b1b85fec0cebb
Author: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
Date: Thu Mar 26 11:45:21 2026 -0700
feat(generator): Apache 2.0 license on generated CLIs with NOTICE attribution
The printing press itself stays MIT. Every CLI it generates ships with:
- Apache 2.0 LICENSE file (patent grant + NOTICE preservation requirement)
- NOTICE file crediting CLI Printing Press and Matt Van Horn
- Apache 2.0 SPDX header on every generated .go file:
"Copyright {year} {owner}. Licensed under Apache-2.0. See LICENSE."
"Generated by CLI Printing Press (github.com/mvanhorn/cli-printing-press)"
Companies that ship CLIs generated by the press must preserve the NOTICE
file in their distribution. This is the standard approach used by protoc,
OpenAPI Generator, and Swagger Codegen.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---
internal/generator/generator.go | 5 +
internal/generator/generator_test.go | 8 +-
internal/generator/templates/LICENSE.tmpl | 191 +++++++++++++++++++++
internal/generator/templates/NOTICE.tmpl | 8 +
internal/generator/templates/analytics.go.tmpl | 3 +-
internal/generator/templates/auth.go.tmpl | 3 +-
internal/generator/templates/auth_simple.go.tmpl | 110 ++++++++++++
internal/generator/templates/cache.go.tmpl | 59 +++++++
.../generator/templates/channel_workflow.go.tmpl | 3 +-
internal/generator/templates/client.go.tmpl | 3 +-
internal/generator/templates/command.go.tmpl | 3 +-
.../generator/templates/command_endpoint.go.tmpl | 183 ++++++++++++++++++++
.../generator/templates/command_parent.go.tmpl | 22 +++
internal/generator/templates/config.go.tmpl | 3 +-
internal/generator/templates/doctor.go.tmpl | 3 +-
internal/generator/templates/export.go.tmpl | 3 +-
internal/generator/templates/helpers.go.tmpl | 3 +-
internal/generator/templates/import.go.tmpl | 3 +-
.../templates/insights/health_score.go.tmpl | 3 +-
.../generator/templates/insights/similar.go.tmpl | 3 +-
internal/generator/templates/main.go.tmpl | 3 +-
internal/generator/templates/root.go.tmpl | 3 +-
internal/generator/templates/search.go.tmpl | 3 +-
internal/generator/templates/store.go.tmpl | 3 +-
internal/generator/templates/sync.go.tmpl | 3 +-
internal/generator/templates/tail.go.tmpl | 3 +-
internal/generator/templates/types.go.tmpl | 3 +-
.../generator/templates/workflows/pm_load.go.tmpl | 3 +-
.../templates/workflows/pm_orphans.go.tmpl | 3 +-
.../generator/templates/workflows/pm_stale.go.tmpl | 3 +-
30 files changed, 626 insertions(+), 26 deletions(-)
diff --git a/internal/generator/generator.go b/internal/generator/generator.go
index dc2dd807..3ee87de1 100644
--- a/internal/generator/generator.go
+++ b/internal/generator/generator.go
@@ -5,8 +5,10 @@ import (
"fmt"
"os"
"path/filepath"
+ "strconv"
"strings"
"text/template"
+ "time"
"unicode"
"github.com/mvanhorn/cli-printing-press/internal/profiler"
@@ -49,6 +51,7 @@ func New(s *spec.APISpec, outputDir string) *Generator {
"flagName": flagName,
"safeTypeName": safeTypeName,
"exampleLine": g.exampleLine,
+ "currentYear": func() string { return strconv.Itoa(time.Now().Year()) },
}
return g
}
@@ -82,6 +85,8 @@ func (g *Generator) Generate() error {
"golangci.yml.tmpl": ".golangci.yml",
"makefile.tmpl": "Makefile",
"readme.md.tmpl": "README.md",
+ "LICENSE.tmpl": "LICENSE",
+ "NOTICE.tmpl": "NOTICE",
}
for tmplName, outPath := range singleFiles {
diff --git a/internal/generator/generator_test.go b/internal/generator/generator_test.go
index 0290be66..920e53c7 100644
--- a/internal/generator/generator_test.go
+++ b/internal/generator/generator_test.go
@@ -21,9 +21,9 @@ func TestGenerateProjectsCompile(t *testing.T) {
specPath string
expectedFiles int
}{
- {name: "stytch", specPath: filepath.Join("..", "..", "testdata", "stytch.yaml"), expectedFiles: 26},
- {name: "clerk", specPath: filepath.Join("..", "..", "testdata", "clerk.yaml"), expectedFiles: 31},
- {name: "loops", specPath: filepath.Join("..", "..", "testdata", "loops.yaml"), expectedFiles: 29},
+ {name: "stytch", specPath: filepath.Join("..", "..", "testdata", "stytch.yaml"), expectedFiles: 28},
+ {name: "clerk", specPath: filepath.Join("..", "..", "testdata", "clerk.yaml"), expectedFiles: 33},
+ {name: "loops", specPath: filepath.Join("..", "..", "testdata", "loops.yaml"), expectedFiles: 31},
}
for _, tt := range tests {
@@ -273,7 +273,7 @@ func TestGeneratedOutput_HasGenerationComment(t *testing.T) {
require.NotEmpty(t, entries, "cmd/ should have at least one subdirectory")
mainGo, err := os.ReadFile(filepath.Join(outputDir, "cmd", entries[0].Name(), "main.go"))
require.NoError(t, err)
- assert.True(t, strings.Contains(string(mainGo), "Code generated by CLI Printing Press"), "main.go should contain generation comment")
+ assert.True(t, strings.Contains(string(mainGo), "Generated by CLI Printing Press"), "main.go should contain generation comment")
}
func TestGeneratedOutput_READMEHasQuickStart(t *testing.T) {
diff --git a/internal/generator/templates/LICENSE.tmpl b/internal/generator/templates/LICENSE.tmpl
new file mode 100644
index 00000000..f222292d
--- /dev/null
+++ b/internal/generator/templates/LICENSE.tmpl
@@ -0,0 +1,191 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to the Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by the Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding any notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ Copyright {{currentYear}} {{.Owner}}
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/internal/generator/templates/NOTICE.tmpl b/internal/generator/templates/NOTICE.tmpl
new file mode 100644
index 00000000..cda032c5
--- /dev/null
+++ b/internal/generator/templates/NOTICE.tmpl
@@ -0,0 +1,8 @@
+{{.Name}}-cli
+Copyright {{currentYear}} {{.Owner}}
+
+This CLI was generated by CLI Printing Press (https://github.com/mvanhorn/cli-printing-press)
+by Matt Van Horn. The Non-Obvious Insight, domain archetype detection, workflow commands,
+and behavioral insight commands were produced by the printing press's creative vision engine.
+
+CLI Printing Press is licensed separately under the MIT License.
diff --git a/internal/generator/templates/analytics.go.tmpl b/internal/generator/templates/analytics.go.tmpl
index 122666f8..572a1c44 100644
--- a/internal/generator/templates/analytics.go.tmpl
+++ b/internal/generator/templates/analytics.go.tmpl
@@ -1,4 +1,5 @@
-// Code generated by CLI Printing Press. DO NOT EDIT.
+// Copyright {{currentYear}} {{.Owner}}. Licensed under Apache-2.0. See LICENSE.
+// Generated by CLI Printing Press (https://github.com/mvanhorn/cli-printing-press). DO NOT EDIT.
package cli
diff --git a/internal/generator/templates/auth.go.tmpl b/internal/generator/templates/auth.go.tmpl
index 89c92c93..e20b5fcd 100644
--- a/internal/generator/templates/auth.go.tmpl
+++ b/internal/generator/templates/auth.go.tmpl
@@ -1,4 +1,5 @@
-// Code generated by CLI Printing Press. DO NOT EDIT.
+// Copyright {{currentYear}} {{.Owner}}. Licensed under Apache-2.0. See LICENSE.
+// Generated by CLI Printing Press (https://github.com/mvanhorn/cli-printing-press). DO NOT EDIT.
package cli
diff --git a/internal/generator/templates/auth_simple.go.tmpl b/internal/generator/templates/auth_simple.go.tmpl
new file mode 100644
index 00000000..b5c90e8c
--- /dev/null
+++ b/internal/generator/templates/auth_simple.go.tmpl
@@ -0,0 +1,110 @@
+// Copyright {{currentYear}} {{.Owner}}. Licensed under Apache-2.0. See LICENSE.
+// Generated by CLI Printing Press (https://github.com/mvanhorn/cli-printing-press). DO NOT EDIT.
+
+package cli
+
+import (
+ "fmt"
+{{- if .Auth.EnvVars}}
+ "os"
+{{- end}}
+
+ "github.com/{{.Owner}}/{{.Name}}-cli/internal/config"
+ "github.com/spf13/cobra"
+)
+
+func newAuthCmd(flags *rootFlags) *cobra.Command {
+ cmd := &cobra.Command{
+ Use: "auth",
+ Short: "Manage authentication tokens",
+ }
+
+ cmd.AddCommand(newAuthStatusCmd(flags))
+ cmd.AddCommand(newAuthSetTokenCmd(flags))
+ cmd.AddCommand(newAuthLogoutCmd(flags))
+
+ return cmd
+}
+
+func newAuthStatusCmd(flags *rootFlags) *cobra.Command {
+ return &cobra.Command{
+ Use: "status",
+ Short: "Show authentication status",
+ Example: " {{.Name}}-cli auth status",
+ RunE: func(cmd *cobra.Command, args []string) error {
+ cfg, err := config.Load(flags.configPath)
+ if err != nil {
+ return configErr(err)
+ }
+
+ w := cmd.OutOrStdout()
+ header := cfg.AuthHeader()
+ if header == "" {
+ fmt.Fprintln(w, red("Not authenticated"))
+ fmt.Fprintln(w, "")
+ fmt.Fprintln(w, "Set your token:")
+{{- range .Auth.EnvVars}}
+ fmt.Fprintln(w, " export {{.}}=\"your-token-here\"")
+{{- end}}
+ fmt.Fprintf(w, " {{.Name}}-cli auth set-token <token>\n")
+ return authErr(fmt.Errorf("no credentials configured"))
+ }
+
+ fmt.Fprintln(w, green("Authenticated"))
+ fmt.Fprintf(w, " Source: %s\n", cfg.AuthSource)
+ fmt.Fprintf(w, " Config: %s\n", cfg.Path)
+ return nil
+ },
+ }
+}
+
+func newAuthSetTokenCmd(flags *rootFlags) *cobra.Command {
+ return &cobra.Command{
+ Use: "set-token <token>",
+ Short: "Save an API token to the config file",
+ Example: " {{.Name}}-cli auth set-token sk_live_abc123",
+ Args: cobra.ExactArgs(1),
+ RunE: func(cmd *cobra.Command, args []string) error {
+ cfg, err := config.Load(flags.configPath)
+ if err != nil {
+ return configErr(err)
+ }
+
+ // Save the token directly via the config's save mechanism
+ if err := cfg.SaveTokens("", "", args[0], "", cfg.TokenExpiry); err != nil {
+ return configErr(fmt.Errorf("saving token: %w", err))
+ }
+
+ fmt.Fprintf(cmd.OutOrStdout(), "Token saved to %s\n", cfg.Path)
+ return nil
+ },
+ }
+}
+
+func newAuthLogoutCmd(flags *rootFlags) *cobra.Command {
+ return &cobra.Command{
+ Use: "logout",
+ Short: "Clear stored credentials",
+ Example: " {{.Name}}-cli auth logout",
+ RunE: func(cmd *cobra.Command, args []string) error {
+ cfg, err := config.Load(flags.configPath)
+ if err != nil {
+ return configErr(err)
+ }
+
+ if err := cfg.ClearTokens(); err != nil {
+ return configErr(fmt.Errorf("clearing tokens: %w", err))
+ }
+
+ // Warn if env vars still set
+{{- range .Auth.EnvVars}}
+ if os.Getenv("{{.}}") != "" {
+ fmt.Fprintf(cmd.OutOrStdout(), "Config cleared. Note: {{.}} env var is still set.\n")
+ return nil
+ }
+{{- end}}
+ fmt.Fprintln(cmd.OutOrStdout(), "Logged out. Credentials cleared.")
+ return nil
+ },
+ }
+}
diff --git a/internal/generator/templates/cache.go.tmpl b/internal/generator/templates/cache.go.tmpl
new file mode 100644
index 00000000..66c4c79c
--- /dev/null
+++ b/internal/generator/templates/cache.go.tmpl
@@ -0,0 +1,59 @@
+// Copyright {{currentYear}} {{.Owner}}. Licensed under Apache-2.0. See LICENSE.
+// Generated by CLI Printing Press (https://github.com/mvanhorn/cli-printing-press). DO NOT EDIT.
+
+// Package cache provides a file-based response cache with optional embedded database backend.
+// The default implementation stores JSON responses as flat files in ~/.cache/<cli>/ with a TTL.
+// For higher-throughput or concurrent-write scenarios, replace the file backend with an
+// embedded database such as bolt (go.etcd.io/bbolt), badger (github.com/dgraph-io/badger),
+// or sqlite (modernc.org/sqlite).
+package cache
+
+import (
+ "crypto/sha256"
+ "encoding/hex"
+ "encoding/json"
+ "os"
+ "path/filepath"
+ "time"
+)
+
+// Store is a key-value cache backed by the filesystem.
+type Store struct {
+ Dir string
+ TTL time.Duration
+}
+
+// New creates a file-based cache store.
+func New(dir string, ttl time.Duration) *Store {
+ return &Store{Dir: dir, TTL: ttl}
+}
+
+// Get retrieves a cached value. Returns nil if not found or expired.
+func (s *Store) Get(key string) (json.RawMessage, bool) {
+ path := s.path(key)
+ info, err := os.Stat(path)
+ if err != nil || time.Since(info.ModTime()) > s.TTL {
+ return nil, false
+ }
+ data, err := os.ReadFile(path)
+ if err != nil {
+ return nil, false
+ }
+ return json.RawMessage(data), true
+}
+
+// Set stores a value in the cache.
+func (s *Store) Set(key string, value json.RawMessage) {
+ _ = os.MkdirAll(s.Dir, 0o755)
+ _ = os.WriteFile(s.path(key), []byte(value), 0o644)
+}
+
+// Clear removes all cached entries.
+func (s *Store) Clear() error {
+ return os.RemoveAll(s.Dir)
+}
+
+func (s *Store) path(key string) string {
+ h := sha256.Sum256([]byte(key))
+ return filepath.Join(s.Dir, hex.EncodeToString(h[:8])+".json")
+}
diff --git a/internal/generator/templates/channel_workflow.go.tmpl b/internal/generator/templates/channel_workflow.go.tmpl
index c6129015..cb01725c 100644
--- a/internal/generator/templates/channel_workflow.go.tmpl
+++ b/internal/generator/templates/channel_workflow.go.tmpl
@@ -1,4 +1,5 @@
-// Code generated by CLI Printing Press. DO NOT EDIT.
+// Copyright {{currentYear}} {{.Owner}}. Licensed under Apache-2.0. See LICENSE.
+// Generated by CLI Printing Press (https://github.com/mvanhorn/cli-printing-press). DO NOT EDIT.
package cli
diff --git a/internal/generator/templates/client.go.tmpl b/internal/generator/templates/client.go.tmpl
index dde95f13..249305b5 100644
--- a/internal/generator/templates/client.go.tmpl
+++ b/internal/generator/templates/client.go.tmpl
@@ -1,4 +1,5 @@
-// Code generated by CLI Printing Press. DO NOT EDIT.
+// Copyright {{currentYear}} {{.Owner}}. Licensed under Apache-2.0. See LICENSE.
+// Generated by CLI Printing Press (https://github.com/mvanhorn/cli-printing-press). DO NOT EDIT.
package client
diff --git a/internal/generator/templates/command.go.tmpl b/internal/generator/templates/command.go.tmpl
index 2094e2de..21c2b544 100644
--- a/internal/generator/templates/command.go.tmpl
+++ b/internal/generator/templates/command.go.tmpl
@@ -1,4 +1,5 @@
-// Code generated by CLI Printing Press. DO NOT EDIT.
+// Copyright {{currentYear}} {{.Owner}}. Licensed under Apache-2.0. See LICENSE.
+// Generated by CLI Printing Press (https://github.com/mvanhorn/cli-printing-press). DO NOT EDIT.
package cli
diff --git a/internal/generator/templates/command_endpoint.go.tmpl b/internal/generator/templates/command_endpoint.go.tmpl
new file mode 100644
index 00000000..0278dcf7
--- /dev/null
+++ b/internal/generator/templates/command_endpoint.go.tmpl
@@ -0,0 +1,183 @@
+// Copyright {{currentYear}} {{.Owner}}. Licensed under Apache-2.0. See LICENSE.
+// Generated by CLI Printing Press (https://github.com/mvanhorn/cli-printing-press). DO NOT EDIT.
+
+package cli
+
+import (
+ "encoding/json"
+ "fmt"
+ "io"
+ "os"
+ "strings"
+
+ "github.com/spf13/cobra"
+)
+
+var _ = strings.ReplaceAll // ensure import
+var _ = fmt.Sprintf // ensure import
+var _ = io.ReadAll // ensure import
+var _ = os.Stdin // ensure import
+var _ json.RawMessage // ensure import
+
+func new{{camel .FuncPrefix}}{{camel .EndpointName}}Cmd(flags *rootFlags) *cobra.Command {
+{{- range .Endpoint.Params}}
+{{- if not .Positional}}
+ var flag{{camel .Name}} {{goType .Type}}
+{{- end}}
+{{- end}}
+{{- range .Endpoint.Body}}
+ var body{{camel .Name}} {{goType .Type}}
+{{- end}}
+{{- if .Endpoint.Pagination}}
+ var flagAll bool
+{{- end}}
+{{- if or (eq .Endpoint.Method "POST") (eq .Endpoint.Method "PUT") (eq .Endpoint.Method "PATCH")}}
+ var stdinBody bool
+{{- end}}
+
+ cmd := &cobra.Command{
+ Use: "{{.EndpointName}}{{positionalArgs .Endpoint}}",
+{{- if .Endpoint.Alias}}
+ Aliases: []string{"{{.Endpoint.Alias}}"},
+{{- end}}
+ Short: "{{oneline .Endpoint.Description}}",
+ Example: "{{exampleLine .CommandPath .EndpointName .Endpoint}}",
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := flags.newClient()
+ if err != nil {
+ return err
+ }
+
+ path := "{{.Endpoint.Path}}"
+{{- range $i, $p := .Endpoint.Params}}
+{{- if .Positional}}
+ if len(args) < {{add $i 1}} {
+ return usageErr(fmt.Errorf("{{.Name}} is required"))
+ }
+ path = replacePathParam(path, "{{.Name}}", args[{{$i}}])
+{{- end}}
+{{- end}}
+
+{{- if or (eq .Endpoint.Method "GET") (eq .Endpoint.Method "HEAD")}}
+{{- if .Endpoint.Pagination}}
+ data, err := paginatedGet(c, path, map[string]string{
+{{- range .Endpoint.Params}}
+{{- if not .Positional}}
+ "{{.Name}}": fmt.Sprintf("%v", flag{{camel .Name}}),
+{{- end}}
+{{- end}}
+ }, flagAll, "{{.Endpoint.Pagination.CursorParam}}", "{{.Endpoint.Pagination.NextCursorPath}}", "{{.Endpoint.Pagination.HasMoreField}}")
+{{- else}}
+ params := map[string]string{}
+{{- range .Endpoint.Params}}
+{{- if not .Positional}}
+ if flag{{camel .Name}} != {{zeroVal .Type}} {
+ params["{{.Name}}"] = fmt.Sprintf("%v", flag{{camel .Name}})
+ }
+{{- end}}
+{{- end}}
+ data, err := c.Get(path, params)
+{{- end}}
+{{- else if eq .Endpoint.Method "POST"}}
+ var body map[string]any
+ if stdinBody {
+ stdinData, err := io.ReadAll(os.Stdin)
+ if err != nil {
+ return fmt.Errorf("reading stdin: %w", err)
+ }
+ var jsonBody map[string]any
+ if err := json.Unmarshal(stdinData, &jsonBody); err != nil {
+ return fmt.Errorf("parsing stdin JSON: %w", err)
+ }
+ body = jsonBody
+ } else {
+ body = map[string]any{}
+{{- range .Endpoint.Body}}
+ if body{{camel .Name}} != {{zeroVal .Type}} {
+ body["{{.Name}}"] = body{{camel .Name}}
+ }
+{{- end}}
+ }
+ data, err := c.Post(path, body)
+{{- else if eq .Endpoint.Method "DELETE"}}
+ data, err := c.Delete(path)
+{{- else if eq .Endpoint.Method "PUT"}}
+ var body map[string]any
+ if stdinBody {
+ stdinData, err := io.ReadAll(os.Stdin)
+ if err != nil {
+ return fmt.Errorf("reading stdin: %w", err)
+ }
+ var jsonBody map[string]any
+ if err := json.Unmarshal(stdinData, &jsonBody); err != nil {
+ return fmt.Errorf("parsing stdin JSON: %w", err)
+ }
+ body = jsonBody
+ } else {
+ body = map[string]any{}
+{{- range .Endpoint.Body}}
+ if body{{camel .Name}} != {{zeroVal .Type}} {
+ body["{{.Name}}"] = body{{camel .Name}}
+ }
+{{- end}}
+ }
+ data, err := c.Put(path, body)
+{{- else if eq .Endpoint.Method "PATCH"}}
+ var body map[string]any
+ if stdinBody {
+ stdinData, err := io.ReadAll(os.Stdin)
+ if err != nil {
+ return fmt.Errorf("reading stdin: %w", err)
+ }
+ var jsonBody map[string]any
+ if err := json.Unmarshal(stdinData, &jsonBody); err != nil {
+ return fmt.Errorf("parsing stdin JSON: %w", err)
+ }
+ body = jsonBody
+ } else {
+ body = map[string]any{}
+{{- range .Endpoint.Body}}
+ if body{{camel .Name}} != {{zeroVal .Type}} {
+ body["{{.Name}}"] = body{{camel .Name}}
+ }
+{{- end}}
+ }
+ data, err := c.Patch(path, body)
+{{- end}}
+{{- if eq .Endpoint.Method "DELETE"}}
+ if err != nil {
+ return classifyDeleteError(err)
+ }
+{{- else}}
+ if err != nil {
+ return classifyAPIError(err)
+ }
+{{- end}}
+
+ return printOutput(cmd.OutOrStdout(), data, flags.asJSON)
+ },
+ }
+
+{{- range .Endpoint.Params}}
+{{- if not .Positional}}
+ cmd.Flags().{{cobraFlagFunc .Type}}(&flag{{camel .Name}}, "{{flagName .Name}}", {{defaultVal .}}, "{{oneline .Description}}")
+{{- if .Required}}
+ _ = cmd.MarkFlagRequired("{{flagName .Name}}")
+{{- end}}
+{{- end}}
+{{- end}}
+{{- range .Endpoint.Body}}
+ cmd.Flags().{{cobraFlagFunc .Type}}(&body{{camel .Name}}, "{{flagName .Name}}", {{defaultVal .}}, "{{oneline .Description}}")
+{{- if .Required}}
+ _ = cmd.MarkFlagRequired("{{flagName .Name}}")
+{{- end}}
+{{- end}}
+{{- if .Endpoint.Pagination}}
+ cmd.Flags().BoolVar(&flagAll, "all", false, "Fetch all pages")
+{{- end}}
+{{- if or (eq .Endpoint.Method "POST") (eq .Endpoint.Method "PUT") (eq .Endpoint.Method "PATCH")}}
+ cmd.Flags().BoolVar(&stdinBody, "stdin", false, "Read request body as JSON from stdin")
+{{- end}}
+
+ return cmd
+}
diff --git a/internal/generator/templates/command_parent.go.tmpl b/internal/generator/templates/command_parent.go.tmpl
new file mode 100644
index 00000000..24de3a3d
--- /dev/null
+++ b/internal/generator/templates/command_parent.go.tmpl
@@ -0,0 +1,22 @@
+// Copyright {{currentYear}} {{.Owner}}. Licensed under Apache-2.0. See LICENSE.
+// Generated by CLI Printing Press (https://github.com/mvanhorn/cli-printing-press). DO NOT EDIT.
+
+package cli
+
+import (
+ "github.com/spf13/cobra"
+)
+
+func new{{camel .FuncPrefix}}Cmd(flags *rootFlags) *cobra.Command {
+ cmd := &cobra.Command{
+ Use: "{{.ResourceName}}",
+ Short: "{{oneline .Resource.Description}}",
+ }
+{{range $eName, $endpoint := .Resource.Endpoints}}
+ cmd.AddCommand(new{{camel $.FuncPrefix}}{{camel $eName}}Cmd(flags))
+{{- end}}
+{{- range $subName, $sub := .Resource.SubResources}}
+ cmd.AddCommand(new{{camel $.FuncPrefix}}{{camel $subName}}Cmd(flags))
+{{- end}}
+ return cmd
+}
diff --git a/internal/generator/templates/config.go.tmpl b/internal/generator/templates/config.go.tmpl
index 23cb4454..6f81ae4d 100644
--- a/internal/generator/templates/config.go.tmpl
+++ b/internal/generator/templates/config.go.tmpl
@@ -1,4 +1,5 @@
-// Code generated by CLI Printing Press. DO NOT EDIT.
+// Copyright {{currentYear}} {{.Owner}}. Licensed under Apache-2.0. See LICENSE.
+// Generated by CLI Printing Press (https://github.com/mvanhorn/cli-printing-press). DO NOT EDIT.
package config
diff --git a/internal/generator/templates/doctor.go.tmpl b/internal/generator/templates/doctor.go.tmpl
index 8e993e35..cdee375f 100644
--- a/internal/generator/templates/doctor.go.tmpl
+++ b/internal/generator/templates/doctor.go.tmpl
@@ -1,4 +1,5 @@
-// Code generated by CLI Printing Press. DO NOT EDIT.
+// Copyright {{currentYear}} {{.Owner}}. Licensed under Apache-2.0. See LICENSE.
+// Generated by CLI Printing Press (https://github.com/mvanhorn/cli-printing-press). DO NOT EDIT.
package cli
diff --git a/internal/generator/templates/export.go.tmpl b/internal/generator/templates/export.go.tmpl
index 611cfce5..ded43186 100644
--- a/internal/generator/templates/export.go.tmpl
+++ b/internal/generator/templates/export.go.tmpl
@@ -1,4 +1,5 @@
-// Code generated by CLI Printing Press. DO NOT EDIT.
+// Copyright {{currentYear}} {{.Owner}}. Licensed under Apache-2.0. See LICENSE.
+// Generated by CLI Printing Press (https://github.com/mvanhorn/cli-printing-press). DO NOT EDIT.
package cli
diff --git a/internal/generator/templates/helpers.go.tmpl b/internal/generator/templates/helpers.go.tmpl
index 5d8c97e0..63970861 100644
--- a/internal/generator/templates/helpers.go.tmpl
+++ b/internal/generator/templates/helpers.go.tmpl
@@ -1,4 +1,5 @@
-// Code generated by CLI Printing Press. DO NOT EDIT.
+// Copyright {{currentYear}} {{.Owner}}. Licensed under Apache-2.0. See LICENSE.
+// Generated by CLI Printing Press (https://github.com/mvanhorn/cli-printing-press). DO NOT EDIT.
package cli
diff --git a/internal/generator/templates/import.go.tmpl b/internal/generator/templates/import.go.tmpl
index 776baaf3..3502589c 100644
--- a/internal/generator/templates/import.go.tmpl
+++ b/internal/generator/templates/import.go.tmpl
@@ -1,4 +1,5 @@
-// Code generated by CLI Printing Press. DO NOT EDIT.
+// Copyright {{currentYear}} {{.Owner}}. Licensed under Apache-2.0. See LICENSE.
+// Generated by CLI Printing Press (https://github.com/mvanhorn/cli-printing-press). DO NOT EDIT.
package cli
diff --git a/internal/generator/templates/insights/health_score.go.tmpl b/internal/generator/templates/insights/health_score.go.tmpl
index 7d6e83cb..c8170a24 100644
--- a/internal/generator/templates/insights/health_score.go.tmpl
+++ b/internal/generator/templates/insights/health_score.go.tmpl
@@ -1,4 +1,5 @@
-// Code generated by CLI Printing Press. DO NOT EDIT.
+// Copyright {{currentYear}} {{.Owner}}. Licensed under Apache-2.0. See LICENSE.
+// Generated by CLI Printing Press (https://github.com/mvanhorn/cli-printing-press). DO NOT EDIT.
package cli
diff --git a/internal/generator/templates/insights/similar.go.tmpl b/internal/generator/templates/insights/similar.go.tmpl
index fe1dc82a..c7f58fb3 100644
--- a/internal/generator/templates/insights/similar.go.tmpl
+++ b/internal/generator/templates/insights/similar.go.tmpl
@@ -1,4 +1,5 @@
-// Code generated by CLI Printing Press. DO NOT EDIT.
+// Copyright {{currentYear}} {{.Owner}}. Licensed under Apache-2.0. See LICENSE.
+// Generated by CLI Printing Press (https://github.com/mvanhorn/cli-printing-press). DO NOT EDIT.
package cli
diff --git a/internal/generator/templates/main.go.tmpl b/internal/generator/templates/main.go.tmpl
index bce66af4..fd4caab5 100644
--- a/internal/generator/templates/main.go.tmpl
+++ b/internal/generator/templates/main.go.tmpl
@@ -1,4 +1,5 @@
-// Code generated by CLI Printing Press. DO NOT EDIT.
+// Copyright {{currentYear}} {{.Owner}}. Licensed under Apache-2.0. See LICENSE.
+// Generated by CLI Printing Press (https://github.com/mvanhorn/cli-printing-press). DO NOT EDIT.
package main
diff --git a/internal/generator/templates/root.go.tmpl b/internal/generator/templates/root.go.tmpl
index a99289c4..7fada1a0 100644
--- a/internal/generator/templates/root.go.tmpl
+++ b/internal/generator/templates/root.go.tmpl
@@ -1,4 +1,5 @@
-// Code generated by CLI Printing Press. DO NOT EDIT.
+// Copyright {{currentYear}} {{.Owner}}. Licensed under Apache-2.0. See LICENSE.
+// Generated by CLI Printing Press (https://github.com/mvanhorn/cli-printing-press). DO NOT EDIT.
package cli
diff --git a/internal/generator/templates/search.go.tmpl b/internal/generator/templates/search.go.tmpl
index 85bed156..d03ace94 100644
--- a/internal/generator/templates/search.go.tmpl
+++ b/internal/generator/templates/search.go.tmpl
@@ -1,4 +1,5 @@
-// Code generated by CLI Printing Press. DO NOT EDIT.
+// Copyright {{currentYear}} {{.Owner}}. Licensed under Apache-2.0. See LICENSE.
+// Generated by CLI Printing Press (https://github.com/mvanhorn/cli-printing-press). DO NOT EDIT.
package cli
diff --git a/internal/generator/templates/store.go.tmpl b/internal/generator/templates/store.go.tmpl
index 95fa3c04..f288cc39 100644
--- a/internal/generator/templates/store.go.tmpl
+++ b/internal/generator/templates/store.go.tmpl
@@ -1,4 +1,5 @@
-// Code generated by CLI Printing Press. DO NOT EDIT.
+// Copyright {{currentYear}} {{.Owner}}. Licensed under Apache-2.0. See LICENSE.
+// Generated by CLI Printing Press (https://github.com/mvanhorn/cli-printing-press). DO NOT EDIT.
// Package store provides local SQLite persistence for {{.Name}}-cli.
// Uses modernc.org/sqlite (pure Go, no CGO) for zero-dependency cross-compilation.
diff --git a/internal/generator/templates/sync.go.tmpl b/internal/generator/templates/sync.go.tmpl
index 6944373c..ddaf8768 100644
--- a/internal/generator/templates/sync.go.tmpl
+++ b/internal/generator/templates/sync.go.tmpl
@@ -1,4 +1,5 @@
-// Code generated by CLI Printing Press. DO NOT EDIT.
+// Copyright {{currentYear}} {{.Owner}}. Licensed under Apache-2.0. See LICENSE.
+// Generated by CLI Printing Press (https://github.com/mvanhorn/cli-printing-press). DO NOT EDIT.
package cli
diff --git a/internal/generator/templates/tail.go.tmpl b/internal/generator/templates/tail.go.tmpl
index 97e9a7ed..9c745254 100644
--- a/internal/generator/templates/tail.go.tmpl
+++ b/internal/generator/templates/tail.go.tmpl
@@ -1,4 +1,5 @@
-// Code generated by CLI Printing Press. DO NOT EDIT.
+// Copyright {{currentYear}} {{.Owner}}. Licensed under Apache-2.0. See LICENSE.
+// Generated by CLI Printing Press (https://github.com/mvanhorn/cli-printing-press). DO NOT EDIT.
package cli
diff --git a/internal/generator/templates/types.go.tmpl b/internal/generator/templates/types.go.tmpl
index af7903b4..48c54399 100644
--- a/internal/generator/templates/types.go.tmpl
+++ b/internal/generator/templates/types.go.tmpl
@@ -1,4 +1,5 @@
-// Code generated by CLI Printing Press. DO NOT EDIT.
+// Copyright {{currentYear}} {{.Owner}}. Licensed under Apache-2.0. See LICENSE.
+// Generated by CLI Printing Press (https://github.com/mvanhorn/cli-printing-press). DO NOT EDIT.
package types
{{range $name, $typeDef := .Types}}
diff --git a/internal/generator/templates/workflows/pm_load.go.tmpl b/internal/generator/templates/workflows/pm_load.go.tmpl
index 0b6a6e47..fd0e8852 100644
--- a/internal/generator/templates/workflows/pm_load.go.tmpl
+++ b/internal/generator/templates/workflows/pm_load.go.tmpl
@@ -1,4 +1,5 @@
-// Code generated by CLI Printing Press. DO NOT EDIT.
+// Copyright {{currentYear}} {{.Owner}}. Licensed under Apache-2.0. See LICENSE.
+// Generated by CLI Printing Press (https://github.com/mvanhorn/cli-printing-press). DO NOT EDIT.
package cli
diff --git a/internal/generator/templates/workflows/pm_orphans.go.tmpl b/internal/generator/templates/workflows/pm_orphans.go.tmpl
index 37a0eda7..49000c7a 100644
--- a/internal/generator/templates/workflows/pm_orphans.go.tmpl
+++ b/internal/generator/templates/workflows/pm_orphans.go.tmpl
@@ -1,4 +1,5 @@
-// Code generated by CLI Printing Press. DO NOT EDIT.
+// Copyright {{currentYear}} {{.Owner}}. Licensed under Apache-2.0. See LICENSE.
+// Generated by CLI Printing Press (https://github.com/mvanhorn/cli-printing-press). DO NOT EDIT.
package cli
diff --git a/internal/generator/templates/workflows/pm_stale.go.tmpl b/internal/generator/templates/workflows/pm_stale.go.tmpl
index 565550af..df29627a 100644
--- a/internal/generator/templates/workflows/pm_stale.go.tmpl
+++ b/internal/generator/templates/workflows/pm_stale.go.tmpl
@@ -1,4 +1,5 @@
-// Code generated by CLI Printing Press. DO NOT EDIT.
+// Copyright {{currentYear}} {{.Owner}}. Licensed under Apache-2.0. See LICENSE.
+// Generated by CLI Printing Press (https://github.com/mvanhorn/cli-printing-press). DO NOT EDIT.
package cli
← 307e67c9 docs: rewrite README with NOI as hero, discrawl story, gogcl
·
back to Cli Printing Press
·
feat(scorecard): add Tier 2 domain correctness dimensions bba34c42 →