cmd/torrent: Restore the announce and bencode subcommands
This commit is contained in:
parent
43b2d3ee21
commit
35834100cc
|
@ -10,8 +10,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type AnnounceCmd struct {
|
type AnnounceCmd struct {
|
||||||
Tracker string `arg:"positional"`
|
Tracker string `arg:"positional"`
|
||||||
InfoHash torrent.InfoHash
|
InfoHash torrent.InfoHash `arg:"positional"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func announceErr(flags AnnounceCmd) error {
|
func announceErr(flags AnnounceCmd) error {
|
||||||
|
|
|
@ -2,16 +2,23 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
stdLog "log"
|
stdLog "log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/davecgh/go-spew/spew"
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
|
|
||||||
"github.com/anacrolix/bargle"
|
"github.com/anacrolix/bargle"
|
||||||
"github.com/anacrolix/envpprof"
|
"github.com/anacrolix/envpprof"
|
||||||
xprometheus "github.com/anacrolix/missinggo/v2/prometheus"
|
xprometheus "github.com/anacrolix/missinggo/v2/prometheus"
|
||||||
|
|
||||||
|
"github.com/anacrolix/torrent/bencode"
|
||||||
"github.com/anacrolix/torrent/version"
|
"github.com/anacrolix/torrent/version"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -29,16 +36,14 @@ func main() {
|
||||||
main.Options = append(main.Options, debugFlag.Make())
|
main.Options = append(main.Options, debugFlag.Make())
|
||||||
main.Positionals = append(main.Positionals,
|
main.Positionals = append(main.Positionals,
|
||||||
bargle.Subcommand{Name: "metainfo", Command: metainfoCmd()},
|
bargle.Subcommand{Name: "metainfo", Command: metainfoCmd()},
|
||||||
//bargle.Subcommand{Name: "announce", Command: func() bargle.Command {
|
bargle.Subcommand{Name: "announce", Command: func() bargle.Command {
|
||||||
// var cmd AnnounceCmd
|
var ac AnnounceCmd
|
||||||
// err := p.NewParser().AddParams(
|
cmd := bargle.FromStruct(&ac)
|
||||||
// args.Pos("tracker", &cmd.Tracker),
|
cmd.DefaultAction = func() error {
|
||||||
// args.Pos("infohash", &cmd.InfoHash)).Parse()
|
return announceErr(ac)
|
||||||
// if err != nil {
|
}
|
||||||
// return err
|
return cmd
|
||||||
// }
|
}()},
|
||||||
// return announceErr(cmd)
|
|
||||||
//}()},
|
|
||||||
bargle.Subcommand{Name: "scrape", Command: func() bargle.Command {
|
bargle.Subcommand{Name: "scrape", Command: func() bargle.Command {
|
||||||
var scrapeCfg scrapeCfg
|
var scrapeCfg scrapeCfg
|
||||||
cmd := bargle.FromStruct(&scrapeCfg)
|
cmd := bargle.FromStruct(&scrapeCfg)
|
||||||
|
@ -59,50 +64,55 @@ func main() {
|
||||||
}
|
}
|
||||||
return cmd
|
return cmd
|
||||||
}()},
|
}()},
|
||||||
//bargle.Subcommand{Name:
|
bargle.Subcommand{
|
||||||
// "bencode", Command: func() bargle.Command {
|
Name: "bencode",
|
||||||
// var print func(interface{}) error
|
Command: func() (cmd bargle.Command) {
|
||||||
// if !p.Parse(
|
var print func(interface{}) error
|
||||||
// args.Subcommand("json", func(ctx args.SubCmdCtx) (err error) {
|
cmd.Positionals = append(cmd.Positionals,
|
||||||
// ctx.Parse()
|
bargle.Subcommand{Name: "json", Command: func() (cmd bargle.Command) {
|
||||||
// je := json.NewEncoder(os.Stdout)
|
cmd.DefaultAction = func() error {
|
||||||
// je.SetIndent("", " ")
|
je := json.NewEncoder(os.Stdout)
|
||||||
// print = je.Encode
|
je.SetIndent("", " ")
|
||||||
// return nil
|
print = je.Encode
|
||||||
// }),
|
return nil
|
||||||
// args.Subcommand("spew", func(ctx args.SubCmdCtx) (err error) {
|
}
|
||||||
// ctx.Parse()
|
return
|
||||||
// config := spew.NewDefaultConfig()
|
}()},
|
||||||
// config.DisableCapacities = true
|
bargle.Subcommand{Name: "spew", Command: func() (cmd bargle.Command) {
|
||||||
// config.Indent = " "
|
cmd.DefaultAction = func() error {
|
||||||
// print = func(v interface{}) error {
|
config := spew.NewDefaultConfig()
|
||||||
// config.Dump(v)
|
config.DisableCapacities = true
|
||||||
// return nil
|
config.Indent = " "
|
||||||
// }
|
print = func(v interface{}) error {
|
||||||
// return nil
|
config.Dump(v)
|
||||||
// }),
|
return nil
|
||||||
// ).RanSubCmd {
|
}
|
||||||
// return errors.New("an output type is required")
|
return nil
|
||||||
// }
|
}
|
||||||
// d := bencode.NewDecoder(os.Stdin)
|
return
|
||||||
// p.Defer(func() error {
|
}()})
|
||||||
// for i := 0; ; i++ {
|
d := bencode.NewDecoder(os.Stdin)
|
||||||
// var v interface{}
|
cmd.AfterParseFunc = func(ctx bargle.Context) error {
|
||||||
// err := d.Decode(&v)
|
ctx.AfterParse(func() error {
|
||||||
// if err == io.EOF {
|
for i := 0; ; i++ {
|
||||||
// break
|
var v interface{}
|
||||||
// }
|
err := d.Decode(&v)
|
||||||
// if err != nil {
|
if err == io.EOF {
|
||||||
// return fmt.Errorf("decoding message index %d: %w", i, err)
|
break
|
||||||
// }
|
}
|
||||||
// print(v)
|
if err != nil {
|
||||||
// }
|
return fmt.Errorf("decoding message index %d: %w", i, err)
|
||||||
// return nil
|
}
|
||||||
// })
|
print(v)
|
||||||
// return nil
|
}
|
||||||
// }(),
|
return nil
|
||||||
// Desc: "reads bencoding from stdin into Go native types and spews the result",
|
})
|
||||||
//},
|
return nil
|
||||||
|
}
|
||||||
|
cmd.Desc = "reads bencoding from stdin into Go native types and spews the result"
|
||||||
|
return
|
||||||
|
}(),
|
||||||
|
},
|
||||||
bargle.Subcommand{Name: "version", Command: bargle.Command{
|
bargle.Subcommand{Name: "version", Command: bargle.Command{
|
||||||
DefaultAction: func() error {
|
DefaultAction: func() error {
|
||||||
fmt.Printf("HTTP User-Agent: %q\n", version.DefaultHttpUserAgent)
|
fmt.Printf("HTTP User-Agent: %q\n", version.DefaultHttpUserAgent)
|
||||||
|
|
Loading…
Reference in New Issue