-
Notifications
You must be signed in to change notification settings - Fork 15
/
cmd_export.go
60 lines (49 loc) · 1.34 KB
/
cmd_export.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
package main
import (
"fmt"
"github.com/ipinfo/mmdbctl/lib"
"github.com/ipinfo/cli/lib/complete"
"github.com/ipinfo/cli/lib/complete/predict"
"github.com/spf13/pflag"
)
var predictFormats = []string{"csv", "tsv", "json"}
var completionsExport = &complete.Command{
Flags: map[string]complete.Predictor{
"-h": predict.Nothing,
"--help": predict.Nothing,
"-o": predict.Nothing,
"--out": predict.Nothing,
"-f": predict.Set(predictFormats),
"--format": predict.Set(predictFormats),
"--no-header": predict.Nothing,
},
}
func printHelpExport() {
fmt.Printf(
`Usage: %s export [<opts>] <mmdb_file> [<out_file>]
Options:
General:
--help, -h
show help.
Input/Output:
-o <fname>, --out <fname>
output file name. (e.g. out.csv)
default: <out_file> if specified, otherwise stdout.
Format:
-f <format>, --format <format>
the output file format.
can be "csv", "tsv" or "json".
default: csv if output file ends in ".csv", tsv if ".tsv",
json if ".json", otherwise csv.
--no-header
don't output the header for file formats that include one, like
CSV/TSV/JSON.
default: false.
`, progBase)
}
func cmdExport() error {
f := lib.CmdExportFlags{}
f.Init()
pflag.Parse()
return lib.CmdExport(f, pflag.Args()[1:], printHelpExport)
}