cmd/torrent-metainfo-pprint: Output JSON instead

This commit is contained in:
Matt Joiner 2015-06-22 19:50:29 +10:00
parent b5ee4f602d
commit 348c6406eb
1 changed files with 10 additions and 2 deletions

View File

@ -1,9 +1,11 @@
package main
import (
"encoding/json"
"flag"
"fmt"
"log"
"os"
"github.com/anacrolix/torrent/metainfo"
)
@ -19,8 +21,14 @@ func main() {
}
if *name {
fmt.Printf("%s\n", metainfo.Info.Name)
} else {
fmt.Printf("%+#v\n", metainfo)
continue
}
d := map[string]interface{}{
"Name": metainfo.Info.Name,
"NumPieces": metainfo.Info.NumPieces(),
}
b, _ := json.MarshalIndent(d, "", " ")
os.Stdout.Write(b)
}
os.Stdout.WriteString("\n")
}