func Cat(db *dropbox.Client, args []string) error { rc, e := db.GetFile(mkabs(args[0])) if e != nil { return e } defer rc.Close() if !strings.HasPrefix(rc.ContentType, "text/") { return fmt.Errorf("Not a content type you should cat: %s", rc.ContentType) } _, e = io.Copy(os.Stdout, rc) return e }
func tryCmd(c *dropbox.Client, cname string, args []string) error { if len(args) == 0 { return fmt.Errorf("Last argument needs to be a dropbox path.") } fname := args[len(args)-1] args = args[:len(args)-1] f, e := c.GetFile(mkabs(fname)) if e != nil { return e } defer f.Close() cmd := exec.Command(cname, args...) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr cmd.Stdin = f return cmd.Run() }
func Get(db *dropbox.Client, args []string) error { fname := mkabs(args[0]) destdir, e := os.Getwd() if e != nil { return e } destfile := gpath.Join(destdir, gpath.Base(fname)) r, e := db.GetFile(fname) if e != nil { return e } defer r.Close() fmt.Printf("Saving to %s\n", destfile) dest, e := os.Create(destfile) if e != nil { return e } defer dest.Close() _, e = io.Copy(dest, r) return e }