Skip to content

Commit

Permalink
moved key fmt functions into keystore file
Browse files Browse the repository at this point in the history
  • Loading branch information
aschmahmann committed Jul 30, 2020
1 parent 92e2133 commit 276d370
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 33 deletions.
33 changes: 0 additions & 33 deletions core/commands/fmt.go

This file was deleted.

28 changes: 28 additions & 0 deletions core/commands/keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"io"
"text/tabwriter"

"github.com/libp2p/go-libp2p-core/peer"
mbase "github.com/multiformats/go-multibase"

cmds "github.com/ipfs/go-ipfs-cmds"
cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
options "github.com/ipfs/interface-go-ipfs-core/options"
Expand Down Expand Up @@ -242,6 +245,31 @@ var keyRmCmd = &cmds.Command{
Type: KeyOutputList{},
}

func verifyIDFormatLabel(formatLabel string) error {
switch formatLabel {
case "b58mh":
return nil
case "b36cid":
return nil
}
return fmt.Errorf("invalid output format option")
}

func formatID(id peer.ID, formatLabel string) string {
switch formatLabel {
case "b58mh":
return id.Pretty()
case "b36cid":
if s, err := peer.ToCid(id).StringOfBase(mbase.Base36); err != nil {
panic(err)
} else {
return s
}
default:
panic("unreachable")
}
}

func keyOutputListEncoders() cmds.EncoderFunc {
return cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, list *KeyOutputList) error {
withID, _ := req.Options["l"].(bool)
Expand Down

0 comments on commit 276d370

Please sign in to comment.