File tree 1 file changed +12
-19
lines changed
1 file changed +12
-19
lines changed Original file line number Diff line number Diff line change 1
1
package main
2
2
3
3
import (
4
- "flag "
4
+ "os "
5
5
"github.com/drn/nerd-ls/list"
6
6
"github.com/drn/nerd-ls/format"
7
+ "github.com/jessevdk/go-flags"
7
8
)
8
9
9
- var all = flag .Bool (
10
- "a" ,
11
- false ,
12
- "Include directory entries whose names begin with a dot (.)." ,
13
- )
14
-
15
- var long = flag .Bool (
16
- "l" ,
17
- false ,
18
- "(The lowercase letter ``ell''.) List in long format. (See " +
19
- "below.) If the output is to a terminal, a total sum for all the " +
20
- "file sizes is output on a line before the long listing." ,
21
- )
10
+ var opts struct {
11
+ All bool `short:"a" long:"all" description:"Include directory entries whose names begin with a dot (.)."`
12
+ Long bool `short:"l" long:"long" description:"List in long format."`
13
+ }
22
14
23
15
func main () {
24
- flag .Parse ()
16
+ args , err := flags .ParseArgs (& opts , os .Args )
17
+ if flags .WroteHelp (err ) { return }
25
18
26
19
dir := "."
27
- if len (flag . Args ()) >= 1 { dir = flag . Args ()[ 0 ] }
20
+ if len (args ) > 1 { dir = args [ 1 ] }
28
21
29
22
nodes := list .Fetch (
30
23
dir ,
31
24
map [string ]bool {
32
- "all" : * all ,
33
- "long" : * long ,
25
+ "all" : opts . All ,
26
+ "long" : opts . Long ,
34
27
},
35
28
)
36
29
37
- if * long {
30
+ if opts . Long {
38
31
format .Long (nodes )
39
32
} else {
40
33
format .Compact (nodes )
You can’t perform that action at this time.
0 commit comments