-
Notifications
You must be signed in to change notification settings - Fork 5
/
car.go
49 lines (39 loc) · 803 Bytes
/
car.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
package main
import (
"flag"
"fmt"
"os"
)
func main() {
var err error
c := flag.Bool("c", false, "archive")
x := flag.Bool("x", false, "extract")
file := flag.String("f", "", "file")
verbose := flag.Bool("v", false, "verbose")
flag.Parse()
if *c == *x {
fmt.Fprintf(flag.CommandLine.Output(), "Either option -c or -x must be specified\n")
os.Exit(1)
}
if *file == "" {
fmt.Fprintf(flag.CommandLine.Output(), "Option -f must be specified\n")
os.Exit(1)
}
var a archive = &car{
dupMap: map[uint64]*fixedData{},
verbose: verbose,
}
if *c {
if flag.NArg() == 0 {
fmt.Fprintf(flag.CommandLine.Output(), "Missing path to compress\n")
os.Exit(1)
}
err = a.archive(flag.Args(), *file)
}
if *x {
err = a.extract(*file)
}
if err != nil {
os.Exit(1)
}
}