| 1 | package cmdenv |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | |
| 6 | "github.com/ipfs/boxo/files" |
| 7 | ) |
| 8 | |
| 9 | // GetFileArg returns the next file from the directory or an error |
| 10 | func GetFileArg(it files.DirIterator) (files.File, error) { |
| 11 | if !it.Next() { |
| 12 | err := it.Err() |
| 13 | if err == nil { |
| 14 | err = fmt.Errorf("expected a file argument") |
| 15 | } |
| 16 | return nil, err |
| 17 | } |
| 18 | file := files.FileFromEntry(it) |
| 19 | if file == nil { |
| 20 | return nil, fmt.Errorf("file argument was nil") |
| 21 | } |
| 22 | return file, nil |
| 23 | } |