import (
        "expvar"
        "fmt"
+       "io"
        stdLog "log"
        "net"
        "net/http"
 
        "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"
 
        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{
                        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")