package main import ( "flag" "fmt" "io/ioutil" "net/http" "os" "os/exec" "strings" ) // get branchmap of mercurial repository served over http func branchmap(repository string) (branches map[string]string, err error) { resp, err := http.Get(repository + "/?cmd=branchmap") if err != nil { return } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) branches = make(map[string]string) for _, line := range strings.Split(string(body), "\n") { a := strings.Split(line, " ") branches[a[0]] = a[1] } return } func poi(executable string) (version string, err error) { cmd := exec.Command(executable, "--version") // wait for complete err = cmd.Wait() // return output output, err := cmd.Output() v := strings.Split(string(output), "-") version = v[len(v)-1] return } func main() { helpFlag := flag.Bool("help", false, "Show help information") verboseFlag := flag.Bool("verbose", false, "Print more information") execFlag := flag.String("exec", "poi", "Executable path") repoFlag := flag.String("repo", "https://neueland.iserlohn-fortress.net/smolbote.hg", "Repository path") flag.Parse() // help flag --> show usage and exit if *helpFlag { fmt.Println("Usage:") flag.PrintDefaults() os.Exit(0) } fmt.Println("Getting poi --version") poi_version, err := poi(*execFlag) if err != nil { fmt.Println("error:", err) } fmt.Println(poi_version) // get branchmap fmt.Println("Getting branchmap...") if *verboseFlag { fmt.Println("for repository", *repoFlag) } branches, err := branchmap(*repoFlag) if err != nil { fmt.Println("Error getting branchmap:", err) os.Exit(1) } for branch, commit := range branches { fmt.Println("-", branch, ":", commit[0:len(poi_version)-1]) } }