Skip to content

Commit e533e5d

Browse files
committed
Switch to jessevdk/go-flags for flag parsing.
Adds support for stackable short flags. Closes #8
1 parent 08633de commit e533e5d

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

main.go

+12-19
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,33 @@
11
package main
22

33
import (
4-
"flag"
4+
"os"
55
"github.com/drn/nerd-ls/list"
66
"github.com/drn/nerd-ls/format"
7+
"github.com/jessevdk/go-flags"
78
)
89

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+
}
2214

2315
func main() {
24-
flag.Parse()
16+
args, err := flags.ParseArgs(&opts, os.Args)
17+
if flags.WroteHelp(err) { return }
2518

2619
dir := "."
27-
if len(flag.Args()) >= 1 { dir = flag.Args()[0] }
20+
if len(args) > 1 { dir = args[1] }
2821

2922
nodes := list.Fetch(
3023
dir,
3124
map[string]bool{
32-
"all": *all,
33-
"long": *long,
25+
"all": opts.All,
26+
"long": opts.Long,
3427
},
3528
)
3629

37-
if *long {
30+
if opts.Long {
3831
format.Long(nodes)
3932
} else {
4033
format.Compact(nodes)

0 commit comments

Comments
 (0)