-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add projectID flag option to delete project command #324
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,16 +32,16 @@ func ViewCommand() *cobra.Command { | |
Args: cobra.MaximumNArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
var err error | ||
var projectName string | ||
var projectNameOrID string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. have it just projectName and have different var for projectID. |
||
var project *project.GetProjectOK | ||
|
||
if len(args) > 0 { | ||
projectName = args[0] | ||
projectNameOrID = args[0] | ||
} else { | ||
projectName = prompt.GetProjectNameFromUser() | ||
projectNameOrID = prompt.GetProjectNameFromUser() | ||
} | ||
|
||
project, err = api.GetProject(projectName) | ||
project, err = api.GetProject(projectNameOrID, false) | ||
if err != nil { | ||
log.Errorf("failed to get project: %v", err) | ||
return | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,11 +20,20 @@ import ( | |
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func RepoDelete(projectName, repoName string) error { | ||
func RepoDelete(projectNameOrID, repoName string, useProjectID bool) error { | ||
ctx, client, err := utils.ContextWithClient() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
projectName := projectNameOrID | ||
if useProjectID { | ||
project, err := GetProject(projectNameOrID, useProjectID) | ||
if err != nil { | ||
return err | ||
} | ||
projectName = project.Payload.Name | ||
} | ||
_, err = client.Repository.DeleteRepository(ctx, &repository.DeleteRepositoryParams{ProjectName: projectName, RepositoryName: repoName}) | ||
|
||
if err != nil { | ||
|
@@ -51,11 +60,20 @@ func RepoView(projectName, repoName string) (*repository.GetRepositoryOK, error) | |
return response, nil | ||
} | ||
|
||
func ListRepository(projectName string) (repository.ListRepositoriesOK, error) { | ||
func ListRepository(projectNameOrID string, useProjectID bool) (repository.ListRepositoriesOK, error) { | ||
ctx, client, err := utils.ContextWithClient() | ||
if err != nil { | ||
return repository.ListRepositoriesOK{}, err | ||
} | ||
projectName := projectNameOrID | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wrong wording. |
||
|
||
if useProjectID { | ||
project, err := GetProject(projectNameOrID, useProjectID) | ||
if err != nil { | ||
return repository.ListRepositoriesOK{}, err | ||
} | ||
projectName = project.Payload.Name | ||
} | ||
|
||
response, err := client.Repository.ListRepositories(ctx, &repository.ListRepositoriesParams{ProjectName: projectName}) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,3 +153,8 @@ func PrintFormat[T any](resp T, format string) error { | |
} | ||
return fmt.Errorf("unable to output in the specified '%s' format", format) | ||
} | ||
|
||
func CreateBoolPointer(b bool) *bool { | ||
return &b | ||
} | ||
|
||
Comment on lines
+156
to
+160
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest project ID to be a flag to which you can pass project ids. rather than having it as a boolean. since this would allow the args to always be projectname maintaining consistency.
Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bupd
So are you suggesting to make projectName an optional input for the delete command? Because I was under the understanding that we are giving projectID when we did not know the projectName.
Right now, when we don't give projectName, we enter the prompt mode and again choose projectName. So do we want to change that behavior when the projectID flag is given?