-
Notifications
You must be signed in to change notification settings - Fork 6
/
list_dir.go
75 lines (61 loc) · 1.37 KB
/
list_dir.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"flag"
"fmt"
"os"
"github.com/cyverse/go-irodsclient/fs"
"github.com/cyverse/go-irodsclient/irods/types"
log "github.com/sirupsen/logrus"
)
func main() {
logger := log.WithFields(log.Fields{
"package": "main",
"function": "main",
})
// Parse cli parameters
flag.Parse()
args := flag.Args()
if len(args) != 1 {
fmt.Fprintf(os.Stderr, "Give an iRODS path!\n")
os.Exit(1)
}
inputPath := args[0]
// Read account configuration from YAML file
yaml, err := os.ReadFile("account.yml")
if err != nil {
logger.Error(err)
panic(err)
}
account, err := types.CreateIRODSAccountFromYAML(yaml)
if err != nil {
logger.Error(err)
panic(err)
}
logger.Debugf("Account : %v", account.GetRedacted())
// Create a file system
appName := "list_dir_ticket"
filesystem, err := fs.NewFileSystemWithDefault(account, appName)
if err != nil {
logger.Error(err)
panic(err)
}
defer filesystem.Release()
entries, err := filesystem.List(inputPath)
if err != nil {
logger.Error(err)
panic(err)
}
if len(entries) == 0 {
fmt.Printf("Found no entries in the directory - %s\n", inputPath)
} else {
fmt.Printf("DIR: %s\n", inputPath)
for _, entry := range entries {
if entry.Type == fs.FileEntry {
fmt.Printf("> FILE:\t%s\t%d\n", entry.Path, entry.Size)
} else {
// dir
fmt.Printf("> DIRECTORY:\t%s\n", entry.Path)
}
}
}
}