mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-10 18:57:57 +08:00
add format flag to key rename and remove, defaulting to b36cid; update sharness
This commit is contained in:
parent
a7629a27c0
commit
80e859ef6f
@ -346,12 +346,16 @@ var keyRenameCmd = &cmds.Command{
|
||||
},
|
||||
Options: []cmds.Option{
|
||||
cmds.BoolOption(keyStoreForceOptionName, "f", "Allow to overwrite an existing key."),
|
||||
cmds.StringOption(keyFormatOptionName, "", "output format: b58mh or b36cid").WithDefault("b36cid"),
|
||||
},
|
||||
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
|
||||
api, err := cmdenv.GetApi(env, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = verifyIDFormatLabel(req.Options[keyFormatOptionName].(string)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
name := req.Arguments[0]
|
||||
newName := req.Arguments[1]
|
||||
@ -365,7 +369,7 @@ var keyRenameCmd = &cmds.Command{
|
||||
return cmds.EmitOnce(res, &KeyRenameOutput{
|
||||
Was: name,
|
||||
Now: newName,
|
||||
Id: key.ID().Pretty(),
|
||||
Id: formatID(key.ID(), req.Options[keyFormatOptionName].(string)), // key.ID().Pretty(),
|
||||
Overwrite: overwritten,
|
||||
})
|
||||
},
|
||||
@ -391,12 +395,16 @@ var keyRmCmd = &cmds.Command{
|
||||
},
|
||||
Options: []cmds.Option{
|
||||
cmds.BoolOption("l", "Show extra information about keys."),
|
||||
cmds.StringOption(keyFormatOptionName, "f", "output format: b58mh or b36cid").WithDefault("b36cid"),
|
||||
},
|
||||
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
|
||||
api, err := cmdenv.GetApi(env, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = verifyIDFormatLabel(req.Options[keyFormatOptionName].(string)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
names := req.Arguments
|
||||
|
||||
@ -407,7 +415,10 @@ var keyRmCmd = &cmds.Command{
|
||||
return err
|
||||
}
|
||||
|
||||
list = append(list, KeyOutput{Name: name, Id: key.ID().Pretty()})
|
||||
list = append(list, KeyOutput{
|
||||
Name: name,
|
||||
Id: formatID(key.ID(), req.Options[keyFormatOptionName].(string)), // key.ID().Pretty(),
|
||||
})
|
||||
}
|
||||
|
||||
return cmds.EmitOnce(res, &KeyOutputList{list})
|
||||
|
||||
@ -152,7 +152,7 @@ ipfs key rm key_ed25519
|
||||
'
|
||||
|
||||
test_expect_success "key rename rename key output succeeds" '
|
||||
key_content=$(ipfs key gen key1 --type=rsa --size=2048 -f=b58mh) &&
|
||||
key_content=$(ipfs key gen key1 --type=rsa --size=2048) &&
|
||||
ipfs key rename key1 key2 >rs &&
|
||||
echo "Key $key_content renamed to key2" >expect &&
|
||||
test_cmp rs expect
|
||||
|
||||
Loading…
Reference in New Issue
Block a user