-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This command will help to delete a registry by id. Signed-off-by: Akshat <akshat25iiit@gmail.com>
- Loading branch information
1 parent
d729be2
commit 1ab60f5
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package registry | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strconv" | ||
|
||
"github.com/akshatdalton/harbor-cli/cmd/constants" | ||
"github.com/akshatdalton/harbor-cli/cmd/utils" | ||
"github.com/goharbor/go-client/pkg/sdk/v2.0/client/registry" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type deleteRegistryOptions struct { | ||
id int64 | ||
} | ||
|
||
// NewDeleteRegistryCommand creates a new `harbor delete registry` command | ||
func NewDeleteRegistryCommand() *cobra.Command { | ||
var opts deleteRegistryOptions | ||
|
||
cmd := &cobra.Command{ | ||
Use: "registry [NAME|ID]", | ||
Short: "delete registry by name or id", | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
id, err := strconv.Atoi(args[0]) | ||
if err != nil { | ||
fmt.Printf("Invalid argument: %s. Expected an integer.\n", args[0]) | ||
return err | ||
} | ||
opts.id = int64(id) | ||
|
||
credentialName, err := cmd.Flags().GetString(constants.CredentialNameOption) | ||
if err != nil { | ||
return err | ||
} | ||
return runDeleteRegistry(opts, credentialName) | ||
}, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func runDeleteRegistry(opts deleteRegistryOptions, credentialName string) error { | ||
client := utils.GetClientByCredentialName(credentialName) | ||
ctx := context.Background() | ||
response, err := client.Registry.DeleteRegistry(ctx, ®istry.DeleteRegistryParams{ID: opts.id}) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
utils.PrintPayloadInJSONFormat(response) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters