-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (42 loc) · 905 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
package main
import (
"fmt"
"github.com/gosuri/uitable"
flag "github.com/spf13/pflag"
)
func main() {
config := newConfig()
flag.BoolVarP(&config.showHiddenFiles, "all", "a", false, "show hidden files")
flag.BoolVarP(&config.longListingFormat, "long", "l", false, "long listing format")
flag.Parse()
directory := flag.Arg(0)
if directory == "" {
directory = "."
}
files, err := listDirectory(directory, config)
if err != nil {
panic(err)
}
table := uitable.New()
table.Separator = " "
for _, f := range files {
if !config.showHiddenFiles && f.isHidden {
continue
}
if config.longListingFormat {
// Right align the size column
table.RightAlign(3)
table.AddRow(
f.mode,
f.user,
f.group,
fmt.Sprintf("%d", f.size),
f.modificationTime.Format("Jan 02 15:04"),
f.name,
)
} else {
table.AddRow(f.name)
}
}
fmt.Println(table)
}