Refactor
Signed-off-by: Oliver Davies <oliver@oliverdavies.uk>
This commit is contained in:
parent
590109b425
commit
a28e1cb7a0
7 changed files with 40 additions and 26 deletions
|
@ -52,7 +52,9 @@ zet edit|e latest
|
|||
os.Exit(0)
|
||||
}
|
||||
|
||||
zets := zet.ParseZetList(ids)
|
||||
zetList := zet.CreateZetList(ids)
|
||||
|
||||
zets := zetList.Parse()
|
||||
|
||||
selected, err := fzf.SelectWithFzf(zets)
|
||||
|
||||
|
|
|
@ -27,7 +27,9 @@ If -j or --json is added, the results will be in JSON format.`,
|
|||
|
||||
zets := zet.SearchZets(args[0])
|
||||
|
||||
result := zet.ParseZetList(zets)
|
||||
zetList := zet.CreateZetList(zets)
|
||||
|
||||
result := zetList.Parse()
|
||||
|
||||
if jsonOutput {
|
||||
json, err := json.AsJSON(result)
|
||||
|
|
|
@ -23,7 +23,9 @@ var linksCmd = &cobra.Command{
|
|||
|
||||
zets := zet.SearchZets(args[0])
|
||||
|
||||
lines := zet.ParseZetList(zets)
|
||||
zetList := zet.CreateZetList(zets)
|
||||
|
||||
lines := zetList.Parse()
|
||||
|
||||
for _, line := range lines {
|
||||
line = strings.TrimSpace(line)
|
||||
|
|
|
@ -20,7 +20,9 @@ If -j or --json is added, the results will be in JSON format.`,
|
|||
Run: func(cli *cobra.Command, args []string) {
|
||||
zets := zet.GetAllZets()
|
||||
|
||||
result := zet.ParseZetList(zets)
|
||||
zetList := zet.CreateZetList(zets)
|
||||
|
||||
result := zetList.Parse()
|
||||
|
||||
if jsonOutput {
|
||||
json, err := json.AsJSON(result)
|
||||
|
|
|
@ -52,7 +52,9 @@ zet view|v latest
|
|||
os.Exit(0)
|
||||
}
|
||||
|
||||
zets := zet.ParseZetList(ids)
|
||||
zetList := zet.CreateZetList(ids)
|
||||
|
||||
zets := zetList.Parse()
|
||||
|
||||
selected, err := fzf.SelectWithFzf(zets)
|
||||
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
package zet
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func ParseZetList(ids []int) []string {
|
||||
var lines []string
|
||||
|
||||
green := "\033[32m"
|
||||
reset := "\033[0m"
|
||||
|
||||
for _, num := range ids {
|
||||
line := fmt.Sprintf("%s%s%s %s", green, strconv.Itoa(num), reset, getTitle(num))
|
||||
|
||||
lines = append(lines, line)
|
||||
}
|
||||
|
||||
return lines
|
||||
}
|
|
@ -12,6 +12,31 @@ import (
|
|||
"code.oliverdavies.uk/opdavies/cmd-zet/internal/git"
|
||||
)
|
||||
|
||||
type ZetList struct {
|
||||
Ids []int
|
||||
}
|
||||
|
||||
func CreateZetList(ids []int) *ZetList {
|
||||
return &ZetList{
|
||||
Ids: ids,
|
||||
}
|
||||
}
|
||||
|
||||
func (z *ZetList) Parse() []string {
|
||||
var lines []string
|
||||
|
||||
green := "\033[32m"
|
||||
reset := "\033[0m"
|
||||
|
||||
for _, num := range z.Ids {
|
||||
line := fmt.Sprintf("%s%s%s %s", green, strconv.Itoa(num), reset, getTitle(num))
|
||||
|
||||
lines = append(lines, line)
|
||||
}
|
||||
|
||||
return lines
|
||||
}
|
||||
|
||||
func getTitle(id int) string {
|
||||
return getTitleFromFile(path.Join(strconv.Itoa(id), "index.adoc"))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue