2
0
mirror of synced 2025-02-23 22:28:11 +00:00

cmd/torrent: Add spew-bencoding command

This commit is contained in:
Matt Joiner 2020-12-09 20:01:53 +11:00
parent 143bf42f5e
commit 65db2436fd

View File

@ -4,6 +4,7 @@ package main
import (
"expvar"
"fmt"
"io"
stdLog "log"
"net"
"net/http"
@ -15,6 +16,8 @@ import (
"github.com/alexflint/go-arg"
"github.com/anacrolix/missinggo"
"github.com/anacrolix/torrent/bencode"
"github.com/davecgh/go-spew/spew"
"github.com/dustin/go-humanize"
"golang.org/x/xerrors"
@ -153,8 +156,12 @@ var flags struct {
Debug bool
Stats *bool
*DownloadCmd `arg:"subcommand:download"`
*ListFilesCmd `arg:"subcommand:list-files"`
*DownloadCmd `arg:"subcommand:download"`
*ListFilesCmd `arg:"subcommand:list-files"`
*SpewBencodingCmd `arg:"subcommand:spew-bencoding"`
}
type SpewBencodingCmd struct {
}
//DownloadCmd: &DownloadCmd{
@ -253,6 +260,20 @@ func mainErr() error {
fmt.Println(f.DisplayPath(&info))
}
return nil
case flags.SpewBencodingCmd != nil:
d := bencode.NewDecoder(os.Stdin)
for i := 0; ; i++ {
var v interface{}
err := d.Decode(&v)
if err == io.EOF {
break
}
if err != nil {
return fmt.Errorf("decoding message index %d: %w", i, err)
}
spew.Dump(v)
}
return nil
default:
p.Fail(fmt.Sprintf("unexpected subcommand: %v", p.Subcommand()))
panic("unreachable")