From 035d575f0e72bd1144a814aa6d5209ec1f8efe15 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Tue, 30 Sep 2025 07:00:00 +0100 Subject: [PATCH] Re-add `zet links` --- cmd/find.go | 5 ++++- cmd/links.go | 40 ++++++++++++++++++++++++++++++++++++++++ cmd/root.go | 1 + cmd/titles.go | 7 ++++++- internal/lib/zet.go | 2 -- 5 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 cmd/links.go diff --git a/cmd/find.go b/cmd/find.go index 3cbaa1c..00e9f60 100644 --- a/cmd/find.go +++ b/cmd/find.go @@ -3,6 +3,7 @@ package cmd import ( "fmt" "os" + "strings" "github.com/spf13/cobra" @@ -23,6 +24,8 @@ var findCmd = &cobra.Command{ zets := lib.SearchZets(args[0]) - lib.ParseZetList(zets) + result := lib.ParseZetList(zets) + + fmt.Println(strings.Join(result, "\n")) }, } diff --git a/cmd/links.go b/cmd/links.go new file mode 100644 index 0000000..a31ffbd --- /dev/null +++ b/cmd/links.go @@ -0,0 +1,40 @@ +package cmd + +import ( + "fmt" + "os" + "strings" + + "github.com/spf13/cobra" + + "code.oliverdavies.uk/opdavies/cmd-zet/internal/lib" +) + +var linksCmd = &cobra.Command{ + Use: "links", + Aliases: []string{"l"}, + Short: "TODO", + Long: `zet links QUERY`, + Run: func(cmd *cobra.Command, args []string) { + if len(args) < 1 { + fmt.Println("No query") + + os.Exit(1) + } + + zets := lib.SearchZets(args[0]) + + lines := lib.ParseZetList(zets) + + for _, line := range lines { + line = strings.TrimSpace(line) + + parts := strings.SplitN(line, " ", 2) + + id := parts[0] + title := parts[1] + + fmt.Printf("* link:../%s/index.adoc[%s]\n", id, title) + } + }, +} diff --git a/cmd/root.go b/cmd/root.go index ef42625..ce264fe 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -29,6 +29,7 @@ func init() { rootCmd.AddCommand(createCmd) rootCmd.AddCommand(editCmd) rootCmd.AddCommand(findCmd) + rootCmd.AddCommand(linksCmd) rootCmd.AddCommand(titlesCmd) rootCmd.AddCommand(viewCmd) diff --git a/cmd/titles.go b/cmd/titles.go index 1c509f5..e28f7ca 100644 --- a/cmd/titles.go +++ b/cmd/titles.go @@ -1,6 +1,9 @@ package cmd import ( + "fmt" + "strings" + "github.com/spf13/cobra" "code.oliverdavies.uk/opdavies/cmd-zet/internal/lib" @@ -14,6 +17,8 @@ var titlesCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { zets := lib.GetAllZets() - lib.ParseZetList(zets) + result := lib.ParseZetList(zets) + + fmt.Println(strings.Join(result, "\n")) }, } diff --git a/internal/lib/zet.go b/internal/lib/zet.go index 16ea432..c887a65 100644 --- a/internal/lib/zet.go +++ b/internal/lib/zet.go @@ -130,8 +130,6 @@ func ParseZetList(ids []int) []string { for _, num := range ids { line := fmt.Sprintf("%s%s%s %s", green, strconv.Itoa(num), reset, getTitle(num)) - fmt.Println(line) - lines = append(lines, line) }