Skip to content

Commit

Permalink
feat: config
Browse files Browse the repository at this point in the history
  • Loading branch information
Selyss committed Oct 20, 2023
1 parent 42773cb commit 8dca2aa
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 18 deletions.
38 changes: 38 additions & 0 deletions cmd/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package main

import (
"os"
"path"
)

func getHomeConfig() (string, error) {

config, err := os.UserHomeDir()
if err != nil {
return "", err
}

return path.Join(config, ".cued.json"), nil
}

func getUserConfig() (string, error) {
config, err := os.UserConfigDir()
if err != nil {
return "", err
}

return path.Join(config, "cued", "cued.json"), nil
}

func GetConfig() (string, error) {
config, err := getUserConfig()

Check failure on line 28 in cmd/config.go

View workflow job for this annotation

GitHub Actions / build

config declared and not used
if err != nil {
return "", err
}

config, err = getHomeConfig()
if err != nil {
return "", err
}

}

Check failure on line 38 in cmd/config.go

View workflow job for this annotation

GitHub Actions / build

missing return
45 changes: 27 additions & 18 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,38 @@ func main() {
log.Fatal(err)
}

url := "cht.sh/%s"
// if there are args we wanna process them
if *topic != "" {
url := "cht.sh/%s"

if *query != "" {
url = fmt.Sprintf(url+"/%s", *topic, *query)
} else {
url = fmt.Sprintf(url, *topic)
}
if *query != "" {
url = fmt.Sprintf(url+"/%s", *topic, *query)
} else {
url = fmt.Sprintf(url, *topic)
}

cmd := exec.Command("curl", "-s", url)
cmd.Stderr = os.Stderr
cmd := exec.Command("curl", "-s", url)
cmd.Stderr = os.Stderr

lessCmd := exec.Command("less")
lessCmd.Stdin, _ = cmd.StdoutPipe()
lessCmd.Stdout = os.Stdout
lessCmd := exec.Command("less")
lessCmd.Stdin, _ = cmd.StdoutPipe()
lessCmd.Stdout = os.Stdout

if err := cmd.Start(); err != nil {
log.Fatal(err)
}
if err := cmd.Start(); err != nil {
log.Fatal(err)
}

if err := lessCmd.Run(); err != nil {
log.Fatal(err)
if err := lessCmd.Run(); err != nil {
log.Fatal(err)

}
}

cmd.Wait()

cmd.Wait()
// regular fzf
} else {
// get lang config

// if no config make a list with all options
}
}

0 comments on commit 8dca2aa

Please sign in to comment.