]> Sergey Matveev's repositories - btrtrc.git/commitdiff
cmd/torrent-magnet: Error if arguments are given
authorMatt Joiner <anacrolix@gmail.com>
Tue, 7 Apr 2015 16:15:25 +0000 (02:15 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Tue, 7 Apr 2015 16:15:25 +0000 (02:15 +1000)
Too easy to make this mistake, and then it hangs.

cmd/torrent-magnet/main.go

index 23a037579a5e275140c04fdbdde27af24ebb0be4..2fcd8cd0ec0768bf9c933aefb849f40b4fffa9b1 100644 (file)
@@ -1,6 +1,7 @@
 package main
 
 import (
+       "flag"
        "fmt"
        "os"
 
@@ -10,6 +11,11 @@ import (
 )
 
 func main() {
+       flag.Parse()
+       if flag.NArg() != 0 {
+               fmt.Fprintf(os.Stderr, "%s\n", "torrent-magnet: unexpected positional arguments")
+               os.Exit(2)
+       }
        mi, err := metainfo.Load(os.Stdin)
        if err != nil {
                fmt.Fprintf(os.Stderr, "error reading metainfo from stdin: %s", err)