/
main.go
54 lines (41 loc) · 977 Bytes
/
main.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
package main
import (
"fmt"
"log"
"github.com/erichnascimento/s3-ls/pkg/ls"
"github.com/dustin/go-humanize"
"github.com/tj/docopt"
)
const version = "0.0.1"
const usage = `
Usage:
s3-ls --region <region> <bucket> <file>
Options:
-r, --region region region of bucket
-h, --help output help information
-v, --version output version
`
func main() {
args, err := docopt.Parse(usage, nil, true, version, false)
if err != nil {
log.Fatal(err)
}
region := args["--region"].(string)
bucket := args["<bucket>"].(string)
file := args["<file>"].(string)
cfg := &ls.Config{
Bucket: bucket,
Region: region,
}
files, err := ls.List(file, cfg)
if err != nil {
log.Fatal(err)
}
listFiles(files)
}
func listFiles(files []*ls.FileInfo) {
fmt.Printf("total %d\n", len(files))
for _, f := range files {
fmt.Printf(" %10s %6s %15s %s\n", f.Owner, humanize.Bytes(f.Size), humanize.Time(f.LastModified), f.Name)
}
}