diff --git a/main.go b/main.go index 30ae1ee3..1a2d6a0b 100644 --- a/main.go +++ b/main.go @@ -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) } diff --git a/src/cli/cli.go b/src/cli/cli.go index 3dec2aa4..048a3e1a 100644 --- a/src/cli/cli.go +++ b/src/cli/cli.go @@ -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" diff --git a/src/install/updateversion.go b/src/install/updateversion.go new file mode 100644 index 00000000..b65a9051 --- /dev/null +++ b/src/install/updateversion.go @@ -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] +}