mirror of
https://github.com/dnote/dnote
synced 2026-03-14 22:45:50 +01:00
Check update
This commit is contained in:
parent
ab66b8edad
commit
d623488da7
1 changed files with 40 additions and 3 deletions
43
main.go
43
main.go
|
|
@ -1,9 +1,11 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gopkg.in/yaml.v2"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/user"
|
||||
"sort"
|
||||
|
|
@ -17,6 +19,7 @@ type Note map[string][]string
|
|||
|
||||
const configFilename = ".dnoterc"
|
||||
const dnoteFilename = ".dnote"
|
||||
const version = "v0.0.1"
|
||||
|
||||
func getConfigPath() (string, error) {
|
||||
usr, err := user.Current()
|
||||
|
|
@ -233,16 +236,50 @@ func checkFileExists(filepath string) bool {
|
|||
return !os.IsNotExist(err)
|
||||
}
|
||||
|
||||
func checkUpdates() error {
|
||||
endpoint := "https://api.github.com/repos/dnote-io/cli/releases"
|
||||
resp, err := http.Get(endpoint)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
var x []map[string]interface{}
|
||||
err = json.NewDecoder(resp.Body).Decode(&x)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(x) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
latestRelease := x[0]
|
||||
latestVersion := latestRelease["tag_name"]
|
||||
|
||||
if version != latestVersion {
|
||||
fmt.Println("==")
|
||||
fmt.Printf("Update available: %s\n", latestVersion)
|
||||
fmt.Printf("See: %s\n", x[0]["html_url"])
|
||||
fmt.Println("==\n")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
err := initDnote()
|
||||
check(err)
|
||||
err = checkUpdates()
|
||||
check(err)
|
||||
|
||||
if len(os.Args) < 2 {
|
||||
fmt.Println("Dnote - A command line tool to spontaneously record new learnings\n")
|
||||
fmt.Println("Dnote - Spontaneously capture new engineering lessons\n")
|
||||
fmt.Println("Commands:")
|
||||
fmt.Println(" use [u] - choose the book")
|
||||
fmt.Println(" new [n] - write a new note")
|
||||
fmt.Println(" ls [l] - show books")
|
||||
fmt.Println(" books [b] - show books")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
|
|
@ -258,7 +295,7 @@ func main() {
|
|||
fmt.Println(note)
|
||||
err := writeNote(note)
|
||||
check(err)
|
||||
case "ls", "l", "books":
|
||||
case "books", "b":
|
||||
currentBook, err := getCurrentBook()
|
||||
check(err)
|
||||
books, err := getBooks()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue