Skip to content

Commit caa2084

Browse files
authored
Add guard-rails against passing a filename. (#2)
This would have prevented a recent misuse that confused internal users.
1 parent 0931b89 commit caa2084

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ then writes the result as a
1010
document to standard output.
1111

1212
To build it, just run `go build`.
13+
14+
To test it with the included test archive, run `cat test.dump | ./mongodump-parser`.
15+
(Append `| jq` to that command to improve the output’s legibility.)

main.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ type Report struct {
2929
}
3030

3131
func main() {
32-
colWidth, _, err := term.GetSize(int(os.Stdin.Fd()))
32+
if term.IsTerminal(int(os.Stdin.Fd())) {
33+
fmt.Fprintf(os.Stderr, "NOTE: Standard input is a terminal, which is unusual. Did you maybe mean to `cat` an archive file into this tool?\n")
34+
}
35+
36+
colWidth, _, err := term.GetSize(int(os.Stdout.Fd()))
3337
if err != nil {
3438
colWidth = defaultColumnWidth
3539
}
@@ -39,6 +43,10 @@ func main() {
3943
Usage: "parse mongodump archive files",
4044
Description: wordwrap.WrapString("This tool reads a mongodump archive file from standard input, parses its header, then outputs the parse to standard output in MongoDB Extended JSON. This lets you see an archive’s contents without actually restoring it.", uint(colWidth-4)),
4145
Action: func(_ context.Context, cmd *cli.Command) error {
46+
if cmd.Args().Len() > 0 {
47+
return fmt.Errorf("unrecognized: %v", cmd.Args().Slice())
48+
}
49+
4250
return run(cmd)
4351
},
4452
}

0 commit comments

Comments
 (0)