From 212f1ca593183af28f82b1a80603b2652d8d56e9 Mon Sep 17 00:00:00 2001 From: Matthew Stobbs Date: Tue, 31 Mar 2026 19:58:19 -0600 Subject: [PATCH] add list_licenses command - List registered licenses on cli --- cmd/list_licenses.go | 49 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 cmd/list_licenses.go diff --git a/cmd/list_licenses.go b/cmd/list_licenses.go new file mode 100644 index 0000000..4116c66 --- /dev/null +++ b/cmd/list_licenses.go @@ -0,0 +1,49 @@ +/* +Copyright © 2026 Matthew Stobbs + +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. +*/ +package cmd + +import ( + "fmt" + "strings" + + "github.com/spf13/cobra" +) + +// listLicensesCmd represents the listLicenses command +var listLicensesCmd = &cobra.Command{ + Use: "list_licenses", + Aliases: []string{"list", "licenses"}, + Short: "List available licenses", + Long: `List licenses that are registered`, + Run: func(_ *cobra.Command, args []string) { + var listSB strings.Builder + listSB.WriteString("List of defined licenses:\n") + for k, v := range Licenses { + listSB.WriteString("\nName: ") + listSB.WriteString(k) + listSB.WriteString("\n Proper name: ") + listSB.WriteString(v.Name) + listSB.WriteString("\n Matches: ") + listSB.WriteString(strings.Join(v.PossibleMatches, " ")) + listSB.WriteRune('\n') + } + fmt.Println(listSB.String()) + }, +} + +func init() { + rootCmd.AddCommand(listLicensesCmd) +}