mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-01 16:05:47 +08:00
cmds: use MakeTypedEncoder
License: MIT Signed-off-by: Overbool <overbool.xu@gmail.com>
This commit is contained in:
@ -112,26 +112,21 @@ var bitswapStatCmd = &cmds.Command{
|
||||
return cmds.EmitOnce(res, st)
|
||||
},
|
||||
Encoders: cmds.EncoderMap{
|
||||
cmds.Text: cmds.MakeEncoder(func(req *cmds.Request, w io.Writer, v interface{}) error {
|
||||
out, ok := v.(*bitswap.Stat)
|
||||
if !ok {
|
||||
return e.TypeErr(out, v)
|
||||
}
|
||||
|
||||
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, s *bitswap.Stat) error {
|
||||
fmt.Fprintln(w, "bitswap status")
|
||||
fmt.Fprintf(w, "\tprovides buffer: %d / %d\n", out.ProvideBufLen, bitswap.HasBlockBufferSize)
|
||||
fmt.Fprintf(w, "\tblocks received: %d\n", out.BlocksReceived)
|
||||
fmt.Fprintf(w, "\tblocks sent: %d\n", out.BlocksSent)
|
||||
fmt.Fprintf(w, "\tdata received: %d\n", out.DataReceived)
|
||||
fmt.Fprintf(w, "\tdata sent: %d\n", out.DataSent)
|
||||
fmt.Fprintf(w, "\tdup blocks received: %d\n", out.DupBlksReceived)
|
||||
fmt.Fprintf(w, "\tdup data received: %s\n", humanize.Bytes(out.DupDataReceived))
|
||||
fmt.Fprintf(w, "\twantlist [%d keys]\n", len(out.Wantlist))
|
||||
for _, k := range out.Wantlist {
|
||||
fmt.Fprintf(w, "\tprovides buffer: %d / %d\n", s.ProvideBufLen, bitswap.HasBlockBufferSize)
|
||||
fmt.Fprintf(w, "\tblocks received: %d\n", s.BlocksReceived)
|
||||
fmt.Fprintf(w, "\tblocks sent: %d\n", s.BlocksSent)
|
||||
fmt.Fprintf(w, "\tdata received: %d\n", s.DataReceived)
|
||||
fmt.Fprintf(w, "\tdata sent: %d\n", s.DataSent)
|
||||
fmt.Fprintf(w, "\tdup blocks received: %d\n", s.DupBlksReceived)
|
||||
fmt.Fprintf(w, "\tdup data received: %s\n", humanize.Bytes(s.DupDataReceived))
|
||||
fmt.Fprintf(w, "\twantlist [%d keys]\n", len(s.Wantlist))
|
||||
for _, k := range s.Wantlist {
|
||||
fmt.Fprintf(w, "\t\t%s\n", k.String())
|
||||
}
|
||||
fmt.Fprintf(w, "\tpartners [%d]\n", len(out.Peers))
|
||||
for _, p := range out.Peers {
|
||||
fmt.Fprintf(w, "\tpartners [%d]\n", len(s.Peers))
|
||||
for _, p := range s.Peers {
|
||||
fmt.Fprintf(w, "\t\t%s\n", p)
|
||||
}
|
||||
|
||||
@ -172,6 +167,7 @@ prints the ledger associated with a given peer.
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cmds.EmitOnce(res, bs.LedgerForPeer(partner))
|
||||
},
|
||||
Encoders: cmds.EncoderMap{
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
|
||||
util "github.com/ipfs/go-ipfs/blocks/blockstoreutil"
|
||||
cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
|
||||
e "github.com/ipfs/go-ipfs/core/commands/e"
|
||||
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
|
||||
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
|
||||
|
||||
@ -83,11 +82,7 @@ on raw IPFS blocks. It outputs the following to stdout:
|
||||
},
|
||||
Type: BlockStat{},
|
||||
Encoders: cmds.EncoderMap{
|
||||
cmds.Text: cmds.MakeEncoder(func(req *cmds.Request, w io.Writer, v interface{}) error {
|
||||
bs, ok := v.(*BlockStat)
|
||||
if !ok {
|
||||
return e.TypeErr(bs, v)
|
||||
}
|
||||
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, bs *BlockStat) error {
|
||||
_, err := fmt.Fprintf(w, "%s", bs)
|
||||
return err
|
||||
}),
|
||||
@ -194,11 +189,7 @@ than 'sha2-256' or format to anything other than 'v0' will result in CIDv1.
|
||||
})
|
||||
},
|
||||
Encoders: cmds.EncoderMap{
|
||||
cmds.Text: cmds.MakeEncoder(func(req *cmds.Request, w io.Writer, v interface{}) error {
|
||||
bs, ok := v.(*BlockStat)
|
||||
if !ok {
|
||||
return e.TypeErr(bs, v)
|
||||
}
|
||||
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, bs *BlockStat) error {
|
||||
_, err := fmt.Fprintf(w, "%s\n", bs.Key)
|
||||
return err
|
||||
}),
|
||||
|
@ -7,8 +7,6 @@ import (
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
"github.com/ipfs/go-ipfs/core/commands/e"
|
||||
|
||||
cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
|
||||
verifcid "gx/ipfs/QmYMQuypUbgsdNHmuCBSUJV6wdQVsBHRivNAp3efHJwZJD/go-verifcid"
|
||||
cmds "gx/ipfs/Qma6uuSyjkecGhMFFLfzyJDPyoDtNJSHJNweDccZhaWkgU/go-ipfs-cmds"
|
||||
@ -245,13 +243,9 @@ var basesCmd = &cmds.Command{
|
||||
return nil
|
||||
},
|
||||
Encoders: cmds.EncoderMap{
|
||||
cmds.Text: cmds.MakeEncoder(func(req *cmds.Request, w io.Writer, val0 interface{}) error {
|
||||
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, val []CodeAndName) error {
|
||||
prefixes, _ := req.Options[prefixOptionName].(bool)
|
||||
numeric, _ := req.Options[numericOptionName].(bool)
|
||||
val, ok := val0.([]CodeAndName)
|
||||
if !ok {
|
||||
return e.TypeErr(val, val0)
|
||||
}
|
||||
sort.Sort(multibaseSorter{val})
|
||||
for _, v := range val {
|
||||
code := v.Code
|
||||
@ -297,12 +291,8 @@ var codecsCmd = &cmds.Command{
|
||||
return nil
|
||||
},
|
||||
Encoders: cmds.EncoderMap{
|
||||
cmds.Text: cmds.MakeEncoder(func(req *cmds.Request, w io.Writer, val0 interface{}) error {
|
||||
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, val []CodeAndName) error {
|
||||
numeric, _ := req.Options[codecsNumericOptionName].(bool)
|
||||
val, ok := val0.([]CodeAndName)
|
||||
if !ok {
|
||||
return e.TypeErr(val, val0)
|
||||
}
|
||||
sort.Sort(codeAndNameSorter{val})
|
||||
for _, v := range val {
|
||||
if numeric {
|
||||
|
@ -6,11 +6,10 @@ import (
|
||||
"text/tabwriter"
|
||||
|
||||
cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
|
||||
"github.com/ipfs/go-ipfs/core/commands/e"
|
||||
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
|
||||
options "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
|
||||
|
||||
"gx/ipfs/Qma6uuSyjkecGhMFFLfzyJDPyoDtNJSHJNweDccZhaWkgU/go-ipfs-cmds"
|
||||
"gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
|
||||
cmds "gx/ipfs/Qma6uuSyjkecGhMFFLfzyJDPyoDtNJSHJNweDccZhaWkgU/go-ipfs-cmds"
|
||||
cmdkit "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
|
||||
)
|
||||
|
||||
var KeyCmd = &cmds.Command{
|
||||
@ -106,13 +105,8 @@ var keyGenCmd = &cmds.Command{
|
||||
})
|
||||
},
|
||||
Encoders: cmds.EncoderMap{
|
||||
cmds.Text: cmds.MakeEncoder(func(req *cmds.Request, w io.Writer, v interface{}) error {
|
||||
k, ok := v.(*KeyOutput)
|
||||
if !ok {
|
||||
return e.TypeErr(k, v)
|
||||
}
|
||||
|
||||
_, err := w.Write([]byte(k.Id + "\n"))
|
||||
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, ko *KeyOutput) error {
|
||||
_, err := w.Write([]byte(ko.Id + "\n"))
|
||||
return err
|
||||
}),
|
||||
},
|
||||
@ -146,7 +140,7 @@ var keyListCmd = &cmds.Command{
|
||||
return cmds.EmitOnce(res, &KeyOutputList{list})
|
||||
},
|
||||
Encoders: cmds.EncoderMap{
|
||||
cmds.Text: keyOutputListMarshaler(),
|
||||
cmds.Text: keyOutputListEncoders(),
|
||||
},
|
||||
Type: KeyOutputList{},
|
||||
}
|
||||
@ -189,16 +183,11 @@ var keyRenameCmd = &cmds.Command{
|
||||
})
|
||||
},
|
||||
Encoders: cmds.EncoderMap{
|
||||
cmds.Text: cmds.MakeEncoder(func(req *cmds.Request, w io.Writer, v interface{}) error {
|
||||
k, ok := v.(*KeyRenameOutput)
|
||||
if !ok {
|
||||
return fmt.Errorf("expected a KeyRenameOutput as command result")
|
||||
}
|
||||
|
||||
if k.Overwrite {
|
||||
fmt.Fprintf(w, "Key %s renamed to %s with overwriting\n", k.Id, k.Now)
|
||||
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, kro *KeyRenameOutput) error {
|
||||
if kro.Overwrite {
|
||||
fmt.Fprintf(w, "Key %s renamed to %s with overwriting\n", kro.Id, kro.Now)
|
||||
} else {
|
||||
fmt.Fprintf(w, "Key %s renamed to %s\n", k.Id, k.Now)
|
||||
fmt.Fprintf(w, "Key %s renamed to %s\n", kro.Id, kro.Now)
|
||||
}
|
||||
return nil
|
||||
}),
|
||||
@ -237,20 +226,15 @@ var keyRmCmd = &cmds.Command{
|
||||
return cmds.EmitOnce(res, &KeyOutputList{list})
|
||||
},
|
||||
Encoders: cmds.EncoderMap{
|
||||
cmds.Text: keyOutputListMarshaler(),
|
||||
cmds.Text: keyOutputListEncoders(),
|
||||
},
|
||||
Type: KeyOutputList{},
|
||||
}
|
||||
|
||||
func keyOutputListMarshaler() cmds.EncoderFunc {
|
||||
return cmds.MakeEncoder(func(req *cmds.Request, w io.Writer, v interface{}) error {
|
||||
func keyOutputListEncoders() cmds.EncoderFunc {
|
||||
return cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, list *KeyOutputList) error {
|
||||
withID, _ := req.Options["l"].(bool)
|
||||
|
||||
list, ok := v.(*KeyOutputList)
|
||||
if !ok {
|
||||
return e.TypeErr(list, v)
|
||||
}
|
||||
|
||||
tw := tabwriter.NewWriter(w, 1, 2, 1, ' ', 0)
|
||||
for _, s := range list.Keys {
|
||||
if withID {
|
||||
|
@ -8,14 +8,13 @@ import (
|
||||
"time"
|
||||
|
||||
cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
|
||||
e "github.com/ipfs/go-ipfs/core/commands/e"
|
||||
options "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
|
||||
nsopts "github.com/ipfs/go-ipfs/namesys/opts"
|
||||
|
||||
path "gx/ipfs/QmRG3XuGwT7GYuAqgWDJBKTzdaHMwAnc1x7J2KHEXNHxzG/go-path"
|
||||
cmds "gx/ipfs/Qma6uuSyjkecGhMFFLfzyJDPyoDtNJSHJNweDccZhaWkgU/go-ipfs-cmds"
|
||||
logging "gx/ipfs/QmcuXC5cxs79ro2cUuHs4HQ2bkDLJUYokwL8aivcX6HW3C/go-log"
|
||||
"gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
|
||||
cmdkit "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
|
||||
)
|
||||
|
||||
var log = logging.Logger("core/commands/ipns")
|
||||
@ -158,12 +157,8 @@ Resolve the value of a dnslink:
|
||||
return nil
|
||||
},
|
||||
Encoders: cmds.EncoderMap{
|
||||
cmds.Text: cmds.MakeEncoder(func(req *cmds.Request, w io.Writer, v interface{}) error {
|
||||
output, ok := v.(*ResolvedPath)
|
||||
if !ok {
|
||||
return e.TypeErr(output, v)
|
||||
}
|
||||
_, err := fmt.Fprintln(w, output.Path)
|
||||
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, rp *ResolvedPath) error {
|
||||
_, err := fmt.Fprintln(w, rp.Path)
|
||||
return err
|
||||
}),
|
||||
},
|
||||
|
@ -6,8 +6,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/ipfs/go-ipfs/core/commands/cmdenv"
|
||||
"github.com/ipfs/go-ipfs/core/commands/e"
|
||||
|
||||
"gx/ipfs/QmSoeYGNm8v8jAF49hX7UwHwkXjoeobSrn9sya5NPPsxXP/go-libp2p-record"
|
||||
"gx/ipfs/Qma6uuSyjkecGhMFFLfzyJDPyoDtNJSHJNweDccZhaWkgU/go-ipfs-cmds"
|
||||
"gx/ipfs/QmcqU6QUDSXprb1518vYDGczrTJTyGwLG9eUa5iNX4xUtS/go-libp2p-peer"
|
||||
@ -57,14 +55,9 @@ var ipnspsStateCmd = &cmds.Command{
|
||||
},
|
||||
Type: ipnsPubsubState{},
|
||||
Encoders: cmds.EncoderMap{
|
||||
cmds.Text: cmds.MakeEncoder(func(req *cmds.Request, w io.Writer, v interface{}) error {
|
||||
output, ok := v.(*ipnsPubsubState)
|
||||
if !ok {
|
||||
return e.TypeErr(output, v)
|
||||
}
|
||||
|
||||
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, ips *ipnsPubsubState) error {
|
||||
var state string
|
||||
if output.Enabled {
|
||||
if ips.Enabled {
|
||||
state = "enabled"
|
||||
} else {
|
||||
state = "disabled"
|
||||
@ -108,7 +101,7 @@ var ipnspsSubsCmd = &cmds.Command{
|
||||
},
|
||||
Type: stringList{},
|
||||
Encoders: cmds.EncoderMap{
|
||||
cmds.Text: stringListMarshaler(),
|
||||
cmds.Text: stringListEncoder(),
|
||||
},
|
||||
}
|
||||
|
||||
@ -144,14 +137,9 @@ var ipnspsCancelCmd = &cmds.Command{
|
||||
},
|
||||
Type: ipnsPubsubCancel{},
|
||||
Encoders: cmds.EncoderMap{
|
||||
cmds.Text: cmds.MakeEncoder(func(req *cmds.Request, w io.Writer, v interface{}) error {
|
||||
output, ok := v.(*ipnsPubsubCancel)
|
||||
if !ok {
|
||||
return e.TypeErr(output, v)
|
||||
}
|
||||
|
||||
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, ipc *ipnsPubsubCancel) error {
|
||||
var state string
|
||||
if output.Canceled {
|
||||
if ipc.Canceled {
|
||||
state = "canceled"
|
||||
} else {
|
||||
state = "no subscription"
|
||||
@ -163,13 +151,8 @@ var ipnspsCancelCmd = &cmds.Command{
|
||||
},
|
||||
}
|
||||
|
||||
func stringListMarshaler() cmds.EncoderFunc {
|
||||
return cmds.MakeEncoder(func(req *cmds.Request, w io.Writer, v interface{}) error {
|
||||
list, ok := v.(*stringList)
|
||||
if !ok {
|
||||
return e.TypeErr(list, v)
|
||||
}
|
||||
|
||||
func stringListEncoder() cmds.EncoderFunc {
|
||||
return cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, list *stringList) error {
|
||||
for _, s := range list.Strings {
|
||||
_, err := fmt.Fprintln(w, s)
|
||||
if err != nil {
|
||||
|
@ -7,12 +7,11 @@ import (
|
||||
"time"
|
||||
|
||||
cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
|
||||
e "github.com/ipfs/go-ipfs/core/commands/e"
|
||||
iface "github.com/ipfs/go-ipfs/core/coreapi/interface"
|
||||
options "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
|
||||
|
||||
cmds "gx/ipfs/Qma6uuSyjkecGhMFFLfzyJDPyoDtNJSHJNweDccZhaWkgU/go-ipfs-cmds"
|
||||
"gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
|
||||
cmdkit "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -139,18 +138,13 @@ Alternatively, publish an <ipfs-path> using a valid PeerID (as listed by
|
||||
})
|
||||
},
|
||||
Encoders: cmds.EncoderMap{
|
||||
cmds.Text: cmds.MakeEncoder(func(req *cmds.Request, w io.Writer, v interface{}) error {
|
||||
entry, ok := v.(*IpnsEntry)
|
||||
if !ok {
|
||||
return e.TypeErr(entry, v)
|
||||
}
|
||||
|
||||
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, ie *IpnsEntry) error {
|
||||
var err error
|
||||
quieter, _ := req.Options[quieterOptionName].(bool)
|
||||
if quieter {
|
||||
_, err = fmt.Fprintln(w, entry.Name)
|
||||
_, err = fmt.Fprintln(w, ie.Name)
|
||||
} else {
|
||||
_, err = fmt.Fprintf(w, "Published to %s: %s\n", entry.Name, entry.Value)
|
||||
_, err = fmt.Fprintf(w, "Published to %s: %s\n", ie.Name, ie.Value)
|
||||
}
|
||||
return err
|
||||
}),
|
||||
|
@ -9,7 +9,6 @@ import (
|
||||
"sort"
|
||||
|
||||
cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
|
||||
e "github.com/ipfs/go-ipfs/core/commands/e"
|
||||
options "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
|
||||
|
||||
cmds "gx/ipfs/Qma6uuSyjkecGhMFFLfzyJDPyoDtNJSHJNweDccZhaWkgU/go-ipfs-cmds"
|
||||
@ -116,35 +115,20 @@ This command outputs data in the following encodings:
|
||||
}
|
||||
},
|
||||
Encoders: cmds.EncoderMap{
|
||||
cmds.Text: cmds.MakeEncoder(func(req *cmds.Request, w io.Writer, v interface{}) error {
|
||||
m, ok := v.(*pubsubMessage)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type: %T", v)
|
||||
}
|
||||
|
||||
_, err := w.Write(m.Data)
|
||||
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, psm *pubsubMessage) error {
|
||||
_, err := w.Write(psm.Data)
|
||||
return err
|
||||
}),
|
||||
"ndpayload": cmds.MakeEncoder(func(req *cmds.Request, w io.Writer, v interface{}) error {
|
||||
m, ok := v.(*pubsubMessage)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type: %T", v)
|
||||
}
|
||||
|
||||
m.Data = append(m.Data, '\n')
|
||||
_, err := w.Write(m.Data)
|
||||
"ndpayload": cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, psm *pubsubMessage) error {
|
||||
psm.Data = append(psm.Data, '\n')
|
||||
_, err := w.Write(psm.Data)
|
||||
return err
|
||||
}),
|
||||
"lenpayload": cmds.MakeEncoder(func(req *cmds.Request, w io.Writer, v interface{}) error {
|
||||
m, ok := v.(*pubsubMessage)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type: %T", v)
|
||||
}
|
||||
"lenpayload": cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, psm *pubsubMessage) error {
|
||||
buf := make([]byte, 8, len(psm.Data)+8)
|
||||
|
||||
buf := make([]byte, 8, len(m.Data)+8)
|
||||
|
||||
n := binary.PutUvarint(buf, uint64(len(m.Data)))
|
||||
buf = append(buf[:n], m.Data...)
|
||||
n := binary.PutUvarint(buf, uint64(len(psm.Data)))
|
||||
buf = append(buf[:n], psm.Data...)
|
||||
_, err := w.Write(buf)
|
||||
return err
|
||||
}),
|
||||
@ -218,15 +202,11 @@ To use, the daemon must be run with '--enable-pubsub-experiment'.
|
||||
},
|
||||
Type: stringList{},
|
||||
Encoders: cmds.EncoderMap{
|
||||
cmds.Text: cmds.MakeEncoder(stringListEncoder),
|
||||
cmds.Text: cmds.MakeTypedEncoder(stringListEncoder),
|
||||
},
|
||||
}
|
||||
|
||||
func stringListEncoder(req *cmds.Request, w io.Writer, v interface{}) error {
|
||||
list, ok := v.(*stringList)
|
||||
if !ok {
|
||||
return e.TypeErr(list, v)
|
||||
}
|
||||
func stringListEncoder(req *cmds.Request, w io.Writer, list *stringList) error {
|
||||
for _, str := range list.Strings {
|
||||
_, err := fmt.Fprintf(w, "%s\n", str)
|
||||
if err != nil {
|
||||
@ -279,6 +259,6 @@ To use, the daemon must be run with '--enable-pubsub-experiment'.
|
||||
},
|
||||
Type: stringList{},
|
||||
Encoders: cmds.EncoderMap{
|
||||
cmds.Text: cmds.MakeEncoder(stringListEncoder),
|
||||
cmds.Text: cmds.MakeTypedEncoder(stringListEncoder),
|
||||
},
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ import (
|
||||
"text/tabwriter"
|
||||
|
||||
cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
|
||||
e "github.com/ipfs/go-ipfs/core/commands/e"
|
||||
corerepo "github.com/ipfs/go-ipfs/core/corerepo"
|
||||
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
|
||||
|
||||
@ -109,16 +108,11 @@ order to reclaim hard disk space.
|
||||
},
|
||||
Type: GcResult{},
|
||||
Encoders: cmds.EncoderMap{
|
||||
cmds.Text: cmds.MakeEncoder(func(req *cmds.Request, w io.Writer, v interface{}) error {
|
||||
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, gcr *GcResult) error {
|
||||
quiet, _ := req.Options[repoQuietOptionName].(bool)
|
||||
|
||||
obj, ok := v.(*GcResult)
|
||||
if !ok {
|
||||
return e.TypeErr(obj, v)
|
||||
}
|
||||
|
||||
if obj.Error != "" {
|
||||
_, err := fmt.Fprintf(w, "Error: %s\n", obj.Error)
|
||||
if gcr.Error != "" {
|
||||
_, err := fmt.Fprintf(w, "Error: %s\n", gcr.Error)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -127,7 +121,7 @@ order to reclaim hard disk space.
|
||||
prefix = ""
|
||||
}
|
||||
|
||||
_, err := fmt.Fprintf(w, "%s%s\n", prefix, obj.Key)
|
||||
_, err := fmt.Fprintf(w, "%s%s\n", prefix, gcr.Key)
|
||||
return err
|
||||
}),
|
||||
},
|
||||
@ -183,12 +177,7 @@ Version string The repo version.
|
||||
},
|
||||
Type: &corerepo.Stat{},
|
||||
Encoders: cmds.EncoderMap{
|
||||
cmds.Text: cmds.MakeEncoder(func(req *cmds.Request, w io.Writer, v interface{}) error {
|
||||
stat, ok := v.(*corerepo.Stat)
|
||||
if !ok {
|
||||
return e.TypeErr(stat, v)
|
||||
}
|
||||
|
||||
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, stat *corerepo.Stat) error {
|
||||
wtr := tabwriter.NewWriter(w, 0, 0, 1, ' ', 0)
|
||||
defer wtr.Flush()
|
||||
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
"time"
|
||||
|
||||
cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
|
||||
e "github.com/ipfs/go-ipfs/core/commands/e"
|
||||
ncmd "github.com/ipfs/go-ipfs/core/commands/name"
|
||||
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
|
||||
options "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
|
||||
@ -16,8 +15,8 @@ import (
|
||||
nsopts "github.com/ipfs/go-ipfs/namesys/opts"
|
||||
path "gx/ipfs/QmRG3XuGwT7GYuAqgWDJBKTzdaHMwAnc1x7J2KHEXNHxzG/go-path"
|
||||
|
||||
"gx/ipfs/Qma6uuSyjkecGhMFFLfzyJDPyoDtNJSHJNweDccZhaWkgU/go-ipfs-cmds"
|
||||
"gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
|
||||
cmds "gx/ipfs/Qma6uuSyjkecGhMFFLfzyJDPyoDtNJSHJNweDccZhaWkgU/go-ipfs-cmds"
|
||||
cmdkit "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -144,13 +143,8 @@ Resolve the value of an IPFS DAG path:
|
||||
return cmds.EmitOnce(res, &ncmd.ResolvedPath{Path: path.Path("/" + rp.Namespace() + "/" + rp.Cid().String())})
|
||||
},
|
||||
Encoders: cmds.EncoderMap{
|
||||
cmds.Text: cmds.MakeEncoder(func(req *cmds.Request, w io.Writer, v interface{}) error {
|
||||
output, ok := v.(*ncmd.ResolvedPath)
|
||||
if !ok {
|
||||
return e.TypeErr(output, v)
|
||||
}
|
||||
|
||||
fmt.Fprintln(w, output.Path.String())
|
||||
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, rp *ncmd.ResolvedPath) error {
|
||||
fmt.Fprintln(w, rp.Path.String())
|
||||
return nil
|
||||
}),
|
||||
},
|
||||
|
@ -7,22 +7,21 @@ import (
|
||||
"path"
|
||||
"sort"
|
||||
|
||||
"github.com/ipfs/go-ipfs/commands"
|
||||
"github.com/ipfs/go-ipfs/core/commands/cmdenv"
|
||||
"github.com/ipfs/go-ipfs/core/commands/e"
|
||||
"github.com/ipfs/go-ipfs/repo"
|
||||
"github.com/ipfs/go-ipfs/repo/fsrepo"
|
||||
commands "github.com/ipfs/go-ipfs/commands"
|
||||
cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
|
||||
repo "github.com/ipfs/go-ipfs/repo"
|
||||
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
|
||||
|
||||
ma "gx/ipfs/QmRKLtwMw131aK7ugC3G7ybpumMz78YrJe5dzneyindvG1/go-multiaddr"
|
||||
inet "gx/ipfs/QmRKbEchaYADxSCyyjhDh4cTrUby8ftXUb8MRLBTHQYupw/go-libp2p-net"
|
||||
mafilter "gx/ipfs/QmSMZwvs3n4GBikZ7hKzT17c3bk65FmyZo2JqtJ16swqCv/multiaddr-filter"
|
||||
iaddr "gx/ipfs/QmUSE3APe1pMFVsUBZUZaKQKERiPteCWvTAERtVQmtXzgE/go-ipfs-addr"
|
||||
pstore "gx/ipfs/QmUymf8fJtideyv3z727BcZUifGBjMZMpCJqu3Gxk5aRUk/go-libp2p-peerstore"
|
||||
"gx/ipfs/Qma6uuSyjkecGhMFFLfzyJDPyoDtNJSHJNweDccZhaWkgU/go-ipfs-cmds"
|
||||
"gx/ipfs/QmbK4EmM2Xx5fmbqK38TGP3PpY66r3tkXLZTcc7dF9mFwM/go-ipfs-config"
|
||||
"gx/ipfs/QmcYC4ayKi7bq8xecEZxHVEuTL6HREZWTTErrSRd1S3Spz/go-libp2p-swarm"
|
||||
cmds "gx/ipfs/Qma6uuSyjkecGhMFFLfzyJDPyoDtNJSHJNweDccZhaWkgU/go-ipfs-cmds"
|
||||
config "gx/ipfs/QmbK4EmM2Xx5fmbqK38TGP3PpY66r3tkXLZTcc7dF9mFwM/go-ipfs-config"
|
||||
swarm "gx/ipfs/QmcYC4ayKi7bq8xecEZxHVEuTL6HREZWTTErrSRd1S3Spz/go-libp2p-swarm"
|
||||
peer "gx/ipfs/QmcqU6QUDSXprb1518vYDGczrTJTyGwLG9eUa5iNX4xUtS/go-libp2p-peer"
|
||||
"gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
|
||||
cmdkit "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
|
||||
)
|
||||
|
||||
type stringList struct {
|
||||
@ -129,12 +128,7 @@ var swarmPeersCmd = &cmds.Command{
|
||||
return cmds.EmitOnce(res, &out)
|
||||
},
|
||||
Encoders: cmds.EncoderMap{
|
||||
cmds.Text: cmds.MakeEncoder(func(req *cmds.Request, w io.Writer, v interface{}) error {
|
||||
ci, ok := v.(*connInfos)
|
||||
if !ok {
|
||||
return e.TypeErr(ci, v)
|
||||
}
|
||||
|
||||
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, ci *connInfos) error {
|
||||
pipfs := ma.ProtocolWithCode(ma.P_IPFS).Name
|
||||
for _, info := range ci.Peers {
|
||||
fmt.Fprintf(w, "%s/%s/%s", info.Addr, pipfs, info.Peer)
|
||||
@ -248,26 +242,22 @@ var swarmAddrsCmd = &cmds.Command{
|
||||
return cmds.EmitOnce(res, &addrMap{Addrs: out})
|
||||
},
|
||||
Encoders: cmds.EncoderMap{
|
||||
cmds.Text: cmds.MakeEncoder(func(req *cmds.Request, w io.Writer, v interface{}) error {
|
||||
m, ok := v.(*addrMap)
|
||||
if !ok {
|
||||
return e.TypeErr(m, v)
|
||||
}
|
||||
|
||||
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, am *addrMap) error {
|
||||
// sort the ids first
|
||||
ids := make([]string, 0, len(m.Addrs))
|
||||
for p := range m.Addrs {
|
||||
ids := make([]string, 0, len(am.Addrs))
|
||||
for p := range am.Addrs {
|
||||
ids = append(ids, p)
|
||||
}
|
||||
sort.Sort(sort.StringSlice(ids))
|
||||
|
||||
for _, p := range ids {
|
||||
paddrs := m.Addrs[p]
|
||||
paddrs := am.Addrs[p]
|
||||
fmt.Fprintf(w, "%s (%d)\n", p, len(paddrs))
|
||||
for _, addr := range paddrs {
|
||||
fmt.Fprintf(w, "\t"+addr+"\n")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}),
|
||||
},
|
||||
@ -314,7 +304,7 @@ var swarmAddrsLocalCmd = &cmds.Command{
|
||||
},
|
||||
Type: stringList{},
|
||||
Encoders: cmds.EncoderMap{
|
||||
cmds.Text: cmds.MakeEncoder(stringListEncoder),
|
||||
cmds.Text: cmds.MakeTypedEncoder(stringListEncoder),
|
||||
},
|
||||
}
|
||||
|
||||
@ -346,7 +336,7 @@ var swarmAddrsListenCmd = &cmds.Command{
|
||||
},
|
||||
Type: stringList{},
|
||||
Encoders: cmds.EncoderMap{
|
||||
cmds.Text: cmds.MakeEncoder(stringListEncoder),
|
||||
cmds.Text: cmds.MakeTypedEncoder(stringListEncoder),
|
||||
},
|
||||
}
|
||||
|
||||
@ -391,7 +381,7 @@ ipfs swarm connect /ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3
|
||||
return cmds.EmitOnce(res, &stringList{output})
|
||||
},
|
||||
Encoders: cmds.EncoderMap{
|
||||
cmds.Text: cmds.MakeEncoder(stringListEncoder),
|
||||
cmds.Text: cmds.MakeTypedEncoder(stringListEncoder),
|
||||
},
|
||||
Type: stringList{},
|
||||
}
|
||||
@ -436,7 +426,7 @@ it will reconnect.
|
||||
return cmds.EmitOnce(res, &stringList{output})
|
||||
},
|
||||
Encoders: cmds.EncoderMap{
|
||||
cmds.Text: cmds.MakeEncoder(stringListEncoder),
|
||||
cmds.Text: cmds.MakeTypedEncoder(stringListEncoder),
|
||||
},
|
||||
Type: stringList{},
|
||||
}
|
||||
@ -532,7 +522,7 @@ Filters default to those specified under the "Swarm.AddrFilters" config key.
|
||||
return cmds.EmitOnce(res, &stringList{output})
|
||||
},
|
||||
Encoders: cmds.EncoderMap{
|
||||
cmds.Text: cmds.MakeEncoder(stringListEncoder),
|
||||
cmds.Text: cmds.MakeTypedEncoder(stringListEncoder),
|
||||
},
|
||||
Type: stringList{},
|
||||
}
|
||||
@ -596,7 +586,7 @@ add your filters to the ipfs config file.
|
||||
return cmds.EmitOnce(res, &stringList{added})
|
||||
},
|
||||
Encoders: cmds.EncoderMap{
|
||||
cmds.Text: cmds.MakeEncoder(stringListEncoder),
|
||||
cmds.Text: cmds.MakeTypedEncoder(stringListEncoder),
|
||||
},
|
||||
Type: stringList{},
|
||||
}
|
||||
@ -669,7 +659,7 @@ remove your filters from the ipfs config file.
|
||||
return cmds.EmitOnce(res, &stringList{removed})
|
||||
},
|
||||
Encoders: cmds.EncoderMap{
|
||||
cmds.Text: cmds.MakeEncoder(stringListEncoder),
|
||||
cmds.Text: cmds.MakeTypedEncoder(stringListEncoder),
|
||||
},
|
||||
Type: stringList{},
|
||||
}
|
||||
|
Reference in New Issue
Block a user