Exemple #1
0
func Share(db *dropbox.Client, args []string) error {
	link, e := db.GetLink(mkabs(args[0]))
	if e != nil {
		return e
	}
	fmt.Println(link.URL)
	return nil
}
Exemple #2
0
func Find(db *dropbox.Client, args []string) error {
	r, e := db.Search(Cwd, args[0], 0)
	if e != nil {
		return e
	}
	for _, m := range r {
		fmt.Println(m.Path)
	}
	return nil
}
Exemple #3
0
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
}
Exemple #4
0
func Ls(db *dropbox.Client, args []string) error {
	md, e := db.GetMetadata(Cwd, true)
	if e != nil {
		return e
	}
	w := tabwriter.NewWriter(os.Stdout, 0, 2, 1, ' ', 0)
	defer w.Flush()
	for _, f := range md.Contents {
		fmt.Fprintf(w, "%d\t%s\t%s\t\n", f.Bytes, f.ModTime().Format(time.Stamp), gpath.Base(f.Path))
	}
	return nil
}
Exemple #5
0
func Whoami(db *dropbox.Client, args []string) error {
	ai, e := db.GetAccountInfo()
	if e != nil {
		return e
	}
	b, e := json.MarshalIndent(ai, "", "   ")
	if e != nil {
		return e
	}
	fmt.Println(string(b))
	return nil
}
Exemple #6
0
func Cd(db *dropbox.Client, args []string) error {
	dest := args[0]
	if dest == ".." {
		Cwd = gpath.Dir(Cwd)
		return nil
	}
	dest = mkabs(dest)
	md, e := db.GetMetadata(dest, false)
	if e != nil {
		return e
	}
	if md.IsDir {
		Cwd = dest
		return nil
	}
	return fmt.Errorf("No such dir: %s", dest)
}
Exemple #7
0
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()
}
Exemple #8
0
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
}
Exemple #9
0
func Put(db *dropbox.Client, args []string) error {
	srcfile := args[0]
	if !gpath.IsAbs(srcfile) {
		srcdir, e := os.Getwd()
		if e != nil {
			return e
		}
		srcfile = gpath.Join(srcdir, srcfile)
	}
	src, e := os.Open(srcfile)
	if e != nil {
		return e
	}
	defer src.Close()
	fi, e := src.Stat()
	if e != nil {
		return e
	}
	destpath := gpath.Join(Cwd, gpath.Base(srcfile))
	fmt.Printf("Uploading to %s\n", destpath)
	_, e = db.AddFile(destpath, src, fi.Size())
	return e
}
Exemple #10
0
func Mkdir(db *dropbox.Client, args []string) error {
	_, e := db.CreateDir(mkabs(args[0]))
	return e
}
Exemple #11
0
func Rm(db *dropbox.Client, args []string) error {
	_, e := db.Delete(mkabs(args[0]))
	return e
}
Exemple #12
0
func Cp(db *dropbox.Client, args []string) error {
	from, to := mkabs(args[0]), mkabs(args[1])
	_, e := db.Copy(from, to)
	return e
}