Re-add zet links
This commit is contained in:
parent
df9fa52c21
commit
035d575f0e
5 changed files with 51 additions and 4 deletions
|
@ -3,6 +3,7 @@ package cmd
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
@ -23,6 +24,8 @@ var findCmd = &cobra.Command{
|
||||||
|
|
||||||
zets := lib.SearchZets(args[0])
|
zets := lib.SearchZets(args[0])
|
||||||
|
|
||||||
lib.ParseZetList(zets)
|
result := lib.ParseZetList(zets)
|
||||||
|
|
||||||
|
fmt.Println(strings.Join(result, "\n"))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
40
cmd/links.go
Normal file
40
cmd/links.go
Normal file
|
@ -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)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
|
@ -29,6 +29,7 @@ func init() {
|
||||||
rootCmd.AddCommand(createCmd)
|
rootCmd.AddCommand(createCmd)
|
||||||
rootCmd.AddCommand(editCmd)
|
rootCmd.AddCommand(editCmd)
|
||||||
rootCmd.AddCommand(findCmd)
|
rootCmd.AddCommand(findCmd)
|
||||||
|
rootCmd.AddCommand(linksCmd)
|
||||||
rootCmd.AddCommand(titlesCmd)
|
rootCmd.AddCommand(titlesCmd)
|
||||||
rootCmd.AddCommand(viewCmd)
|
rootCmd.AddCommand(viewCmd)
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"code.oliverdavies.uk/opdavies/cmd-zet/internal/lib"
|
"code.oliverdavies.uk/opdavies/cmd-zet/internal/lib"
|
||||||
|
@ -14,6 +17,8 @@ var titlesCmd = &cobra.Command{
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
zets := lib.GetAllZets()
|
zets := lib.GetAllZets()
|
||||||
|
|
||||||
lib.ParseZetList(zets)
|
result := lib.ParseZetList(zets)
|
||||||
|
|
||||||
|
fmt.Println(strings.Join(result, "\n"))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,8 +130,6 @@ func ParseZetList(ids []int) []string {
|
||||||
for _, num := range ids {
|
for _, num := range ids {
|
||||||
line := fmt.Sprintf("%s%s%s %s", green, strconv.Itoa(num), reset, getTitle(num))
|
line := fmt.Sprintf("%s%s%s %s", green, strconv.Itoa(num), reset, getTitle(num))
|
||||||
|
|
||||||
fmt.Println(line)
|
|
||||||
|
|
||||||
lines = append(lines, line)
|
lines = append(lines, line)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue