-
Notifications
You must be signed in to change notification settings - Fork 392
/
gzip.go
77 lines (63 loc) · 1.37 KB
/
gzip.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2012-2017 the u-root Authors. All rights reserved
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"flag"
"fmt"
"os"
"path/filepath"
"github.com/u-root/u-root/pkg/gzip"
)
var cmdLine = flag.CommandLine
func usage() {
fmt.Fprintf(os.Stderr, "Usage of %s:\n", filepath.Base(os.Args[0]))
cmdLine.PrintDefaults()
}
func main() {
var opts gzip.Options
cmdLine.Usage = usage
if err := opts.ParseArgs(os.Args, cmdLine); err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
cmdLine.Usage()
os.Exit(2)
}
var input []string
if opts.Stdin {
input = []string{"/dev/stdin"}
} else {
input = cmdLine.Args()
}
for _, path := range input {
f := gzip.File{Path: path, Options: &opts}
if err := f.CheckPath(); err != nil {
if !opts.Quiet {
fmt.Fprintf(os.Stderr, "%s\n", err)
}
continue
}
if err := f.CheckOutputStdout(); err != nil {
if !opts.Quiet {
fmt.Fprintf(os.Stderr, "%s\n", err)
}
os.Exit(1)
}
if err := f.CheckOutputPath(); err != nil {
if !opts.Quiet {
fmt.Fprintf(os.Stderr, "%s\n", err)
}
continue
}
if err := f.Process(); err != nil {
if !opts.Quiet {
fmt.Fprintf(os.Stderr, "%s\n", err)
}
}
if err := f.Cleanup(); err != nil {
if !opts.Quiet {
fmt.Fprintf(os.Stderr, "%s\n", err)
}
continue
}
}
}