diff --git a/cmd/find.go b/cmd/find.go index 0564bc7..817b257 100644 --- a/cmd/find.go +++ b/cmd/find.go @@ -20,15 +20,13 @@ Cobra is a CLI library for Go that empowers applications. This application is a tool to generate the needed files to quickly create a Cobra application.`, Run: func(cmd *cobra.Command, args []string) { - zetDir := "/home/opdavies/Documents/zet" - if len(args) < 1 { fmt.Println("No query") os.Exit(1) } - zets := lib.SearchZets(zetDir, args[0]) + zets := lib.SearchZets(args[0]) lib.ParseZetList(zets) }, diff --git a/cmd/titles.go b/cmd/titles.go index 175ac02..048253b 100644 --- a/cmd/titles.go +++ b/cmd/titles.go @@ -17,9 +17,7 @@ Cobra is a CLI library for Go that empowers applications. This application is a tool to generate the needed files to quickly create a Cobra application.`, Run: func(cmd *cobra.Command, args []string) { - zetDir := "/home/opdavies/Documents/zet" - - zets := lib.GetAllZets(zetDir) + zets := lib.GetAllZets() lib.ParseZetList(zets) }, diff --git a/cmd/view.go b/cmd/view.go index 4ece1d9..d03d299 100644 --- a/cmd/view.go +++ b/cmd/view.go @@ -32,8 +32,6 @@ to quickly create a Cobra application.`, os.Exit(1) } - zetDir := "/home/opdavies/Documents/zet" - - fmt.Println(lib.ViewZet(zetDir, idInt)) + fmt.Println(lib.ViewZet(idInt)) }, } diff --git a/internal/lib/config.go b/internal/lib/config.go new file mode 100644 index 0000000..9d482ae --- /dev/null +++ b/internal/lib/config.go @@ -0,0 +1,5 @@ +package lib + +func GetZetDir() string { + return "/home/opdavies/Documents/zet" +} diff --git a/internal/lib/git.go b/internal/lib/git.go index eda5e53..30abd4a 100644 --- a/internal/lib/git.go +++ b/internal/lib/git.go @@ -2,8 +2,8 @@ package lib import "os/exec" -func execGitCommand(dir string, parts ...string) (string, error) { - args := append([]string{"-C", dir}, parts...) +func execGitCommand(parts ...string) (string, error) { + args := append([]string{"-C", GetZetDir()}, parts...) command := exec.Command("git", args...) output, err := command.CombinedOutput() diff --git a/internal/lib/zet.go b/internal/lib/zet.go index 2de0c21..4ca8c9d 100644 --- a/internal/lib/zet.go +++ b/internal/lib/zet.go @@ -12,8 +12,8 @@ import ( "strings" ) -func GetAllZets(dir string) []int { - zets, err := execGitCommand(dir, "ls-files") +func GetAllZets() []int { + zets, err := execGitCommand("ls-files") if err != nil { log.Println(err) @@ -43,8 +43,8 @@ func GetAllZets(dir string) []int { return sorted } -func SearchZets(dir string, query string) []int { - zets, err := execGitCommand(dir, "grep", "-i", "--name-only", "--word-regex", query) +func SearchZets(query string) []int { + zets, err := execGitCommand("grep", "-i", "--name-only", "--word-regex", query) if err != nil { fmt.Printf("No matches found for %s.\n", query) @@ -93,8 +93,8 @@ func ParseZetList(ids []int) []string { return lines } -func ViewZet(zetDir string, id int) string { - zetPath := path.Join(zetDir, strconv.Itoa(id), "index.adoc") +func ViewZet(id int) string { + zetPath := path.Join(GetZetDir(), strconv.Itoa(id), "index.adoc") return ViewFile(zetPath) } @@ -104,7 +104,7 @@ func getTitle(id int) string { } func getTitleFromFile(filePath string) string { - filePath = path.Join("/home/opdavies/Documents/zet", filePath) + filePath = path.Join(GetZetDir(), filePath) file, err := os.Open(filePath)