@cryptotaxi247 / kubo / commits / 80e859ef6

add format flag to key rename and remove, defaulting to b36cid; update sharness

Petar Maymounkov committed Aug 10, 2020 at 12:02 UTC 80e859ef6f29cc2d2023b54c7ca65bae6113a031
2 files changed +14 -3
core/commands/keystore.go
+13 -2
@@ -346,12 +346,16 @@ var keyRenameCmd = &cmds.Command{
346 },
347 Options: []cmds.Option{
348 cmds.BoolOption(keyStoreForceOptionName, "f", "Allow to overwrite an existing key."),
349 + cmds.StringOption(keyFormatOptionName, "", "output format: b58mh or b36cid").WithDefault("b36cid"),
350 },
351 Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
352 api, err := cmdenv.GetApi(env, req)
353 if err != nil {
354 return err
355 }
356 + if err = verifyIDFormatLabel(req.Options[keyFormatOptionName].(string)); err != nil {
357 + return err
358 + }
359
360 name := req.Arguments[0]
361 newName := req.Arguments[1]
@@ -365,7 +369,7 @@ var keyRenameCmd = &cmds.Command{
369 return cmds.EmitOnce(res, &KeyRenameOutput{
370 Was: name,
371 Now: newName,
368 - Id: key.ID().Pretty(),
372 + Id: formatID(key.ID(), req.Options[keyFormatOptionName].(string)), // key.ID().Pretty(),
373 Overwrite: overwritten,
374 })
375 },
@@ -391,12 +395,16 @@ var keyRmCmd = &cmds.Command{
395 },
396 Options: []cmds.Option{
397 cmds.BoolOption("l", "Show extra information about keys."),
398 + cmds.StringOption(keyFormatOptionName, "f", "output format: b58mh or b36cid").WithDefault("b36cid"),
399 },
400 Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
401 api, err := cmdenv.GetApi(env, req)
402 if err != nil {
403 return err
404 }
405 + if err = verifyIDFormatLabel(req.Options[keyFormatOptionName].(string)); err != nil {
406 + return err
407 + }
408
409 names := req.Arguments
410
@@ -407,7 +415,10 @@ var keyRmCmd = &cmds.Command{
415 return err
416 }
417
410 - list = append(list, KeyOutput{Name: name, Id: key.ID().Pretty()})
418 + list = append(list, KeyOutput{
419 + Name: name,
420 + Id: formatID(key.ID(), req.Options[keyFormatOptionName].(string)), // key.ID().Pretty(),
421 + })
422 }
423
424 return cmds.EmitOnce(res, &KeyOutputList{list})
test/sharness/t0165-keystore.sh
+1 -1
@@ -152,7 +152,7 @@ ipfs key rm key_ed25519
152 '
153
154 test_expect_success "key rename rename key output succeeds" '
155 - key_content=$(ipfs key gen key1 --type=rsa --size=2048 -f=b58mh) &&
155 + key_content=$(ipfs key gen key1 --type=rsa --size=2048) &&
156 ipfs key rename key1 key2 >rs &&
157 echo "Key $key_content renamed to key2" >expect &&
158 test_cmp rs expect