Skip to content

Commit 25bf3c1

Browse files
authored
create delete cmd to delete keys (#5)
* setup way to delete keys * updated README.md
1 parent c2898f2 commit 25bf3c1

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,8 @@ Show fingerprint for a tenancy
4242

4343
> oci-api-keygen list [tenancy]
4444
45+
**Delete**
46+
47+
Delete all the artifacts for a tenancy and remove it from the config file.
48+
49+
> oci-api-keygen delete [tenancy]

cmd/delete.go

+18-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ import (
3737

3838
// deleteCmd represents the delete command
3939
var deleteCmd = &cobra.Command{
40-
Use: "delete",
40+
Use: "delete [tenancy]",
41+
Args: cobra.ExactArgs(1),
4142
Short: "Delete a tenancy and associated files",
4243
Long: `Use to delete and remove the files of a tenancy that may no
4344
longer be necessary.
@@ -47,7 +48,22 @@ longer be necessary.
4748
there are no backups made, so make sure you want to do this before
4849
you actually do it.`,
4950
Run: func(cmd *cobra.Command, args []string) {
50-
fmt.Println("delete called")
51+
t := args[0]
52+
idx := -1
53+
54+
for i, a := range cfg.ApiKeys {
55+
if a.Tenancy == t {
56+
idx = i
57+
}
58+
}
59+
60+
if idx < 0 {
61+
fmt.Printf("tenancy not found : %s\n", t)
62+
} else {
63+
cfg.ApiKeys = append(cfg.ApiKeys[:idx], cfg.ApiKeys[idx+1:]...)
64+
cfg.SaveConfig()
65+
fmt.Printf("deleted tenancy : %s\n", t)
66+
}
5167
},
5268
}
5369

0 commit comments

Comments
 (0)