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