1
0
mirror of https://github.com/schollz/croc.git synced 2024-11-27 12:34:19 +03:00

add go generate code for updating version

This commit is contained in:
Zack Scholl 2019-05-02 13:14:09 -07:00
parent 7377f536fc
commit 9e61f38707
3 changed files with 57 additions and 41 deletions

39
main.go
View File

@ -1,4 +1,5 @@
package main
//go:generate go run src/install/updateversion.go
import (
"fmt"
@ -7,44 +8,6 @@ import (
)
func main() {
// f, _ := os.Create("test.1")
// f.Truncate(8096)
// f.Close()
// file, _ := os.Open("test.1")
// defer file.Close()
// buffer := make([]byte, 4096)
// emptyBuffer := make([]byte, 4096)
// for {
// bytesread, err := file.Read(buffer)
// if err != nil {
// break
// }
// log.Debugln(bytes.Equal(buffer[:bytesread], emptyBuffer[:bytesread]))
// }
// var sender bool
// flag.BoolVar(&sender, "sender", false, "sender")
// flag.Parse()
// c, err := croc.New(sender, "foo")
// if err != nil {
// panic(err)
// }
// if sender {
// err = c.Send(croc.TransferOptions{
// // PathToFile: "../wskeystore/README.md",
// // PathToFile: "./src/croc/croc.go",
// // PathToFiles: []string{"C:\\Users\\zacks\\go\\src\\github.com\\schollz\\croc\\src\\croc\\croc.go", "croc.exe"},
// PathToFiles: []string{"croc2.exe", "croc3.exe"}, //,"croc2.exe", "croc3.exe"},
// //PathToFiles: []string{"README.md"}, //,"croc2.exe", "croc3.exe"},
// KeepPathInRemote: false,
// })
// } else {
// err = c.Receive()
// }
// if err != nil {
// fmt.Println(err)
// }
if err := cli.Run(); err != nil {
fmt.Println(err)
}

View File

@ -21,14 +21,14 @@ import (
var Version string
func Run() (err error) {
// use all of the processors
runtime.GOMAXPROCS(runtime.NumCPU())
app := cli.NewApp()
app.Name = "croc"
if Version == "" {
Version = "dev"
Version = "6.0.0"
}
app.Version = Version
app.Compiled = time.Now()
app.Usage = "easily and securely transfer stuff from one computer to another"

View File

@ -0,0 +1,53 @@
package main
import (
"fmt"
"io/ioutil"
"strings"
)
func main() {
err := run()
if err != nil {
fmt.Println(err)
}
}
func run() (err error) {
b, err := ioutil.ReadFile("README.md")
if err != nil {
return
}
newVersion := GetStringInBetween(string(b), "version-", "-b")
b, err = ioutil.ReadFile("src/cli/cli.go")
if err != nil {
return
}
oldVersion := GetStringInBetween(string(b), `Version = "`, `"`)
if newVersion != oldVersion {
fmt.Printf("new version: '%s'\n", newVersion)
fmt.Printf("old version: '%s'\n", oldVersion)
newCli := strings.Replace(string(b), fmt.Sprintf(`Version = "%s"`, oldVersion), fmt.Sprintf(`Version = "%s"`, newVersion), 1)
err = ioutil.WriteFile("src/cli/cli.go", []byte(newCli), 0644)
} else {
fmt.Printf("current version: '%s'\n", oldVersion)
}
return
}
// GetStringInBetween Returns empty string if no start string found
func GetStringInBetween(str string, start string, end string) (result string) {
s := strings.Index(str, start)
if s == -1 {
return
}
s += len(start)
e := strings.Index(str[s:], end)
if e == -1 {
return
}
e += s
return str[s:e]
}