func docs(c *cli.Context) { fmt.Println("Opening tenet documentation in a new browser window ...") // TODO(waigani) DEMOWARE writeTenetDoc(c, "", "/tmp/tenets.md") err := browser.OpenFile("/tmp/tenets.md") if err != nil { log.Printf("ERROR opening docs in browser: %v", err) } }
func main() { args := flag.Args() switch len(args) { case 0: check(browser.OpenReader(os.Stdin)) case 1: check(browser.OpenFile(args[0])) default: usage() } }
func openURL(data string, isHTML bool) error { if isHTML { tmpfile, err := ioutil.TempFile("", "pmbopenurl") if err != nil { return err } _, err = tmpfile.Write([]byte(data)) if err != nil { return err } err = tmpfile.Close() if err != nil { return err } nameWithSuffix := fmt.Sprintf("%s.html", tmpfile.Name()) err = os.Rename(tmpfile.Name(), nameWithSuffix) if err != nil { return err } go func() { time.Sleep(15 * time.Second) logrus.Infof("cleaning up temporary file: %s", nameWithSuffix) os.Remove(nameWithSuffix) }() logrus.Infof("opening file: %s", nameWithSuffix) return browser.OpenFile(nameWithSuffix) } logrus.Infof("opening url: %s", data) return browser.OpenURL(data) }