file.go 491 Bytes
Newer Older
1 2 3 4 5
package cmdenv

import (
	"fmt"

6
	files "gx/ipfs/QmaXvvAVAQ5ABqM5xtjYmV85xmN5MkWAZsX9H9Fwo4FVXp/go-ipfs-files"
7 8
)

Łukasz Magiera's avatar
Łukasz Magiera committed
9
// GetFileArg returns the next file from the directory or an error
10 11 12 13 14 15 16 17 18 19 20 21 22 23
func GetFileArg(it files.DirIterator) (files.File, error) {
	if !it.Next() {
		err := it.Err()
		if err == nil {
			err = fmt.Errorf("expected a file argument")
		}
		return nil, err
	}
	file := files.FileFromEntry(it)
	if file == nil {
		return nil, fmt.Errorf("file argument was nil")
	}
	return file, nil
}