cmd/torrent: Add spew-bencoding command
This commit is contained in:
parent
143bf42f5e
commit
65db2436fd
@ -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")
|
||||
|
Loading…
x
Reference in New Issue
Block a user