add base resolution to delete
This commit is contained in:
parent
d794a929da
commit
001b1a36e7
1 changed files with 14 additions and 4 deletions
|
|
@ -18,6 +18,7 @@ import (
|
|||
|
||||
type DeleteOptions struct {
|
||||
HttpClient func() (*http.Client, error)
|
||||
BaseRepo func() (ghrepo.Interface, error)
|
||||
IO *iostreams.IOStreams
|
||||
RepoArg string
|
||||
Confirmed bool
|
||||
|
|
@ -30,15 +31,17 @@ func NewCmdDelete(f *cmdutil.Factory, runF func(*DeleteOptions) error) *cobra.Co
|
|||
}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "delete <repository>",
|
||||
Use: "delete [<repository>]",
|
||||
Short: "Delete a repository",
|
||||
Long: `Delete a GitHub repository.
|
||||
|
||||
Deletion requires authorization with the "delete_repo" scope.
|
||||
To authorize, run "gh auth refresh -s delete_repo"`,
|
||||
Args: cmdutil.ExactArgs(1, "cannot delete: repository argument required"),
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
opts.RepoArg = args[0]
|
||||
if len(args) > 0 {
|
||||
opts.RepoArg = args[0]
|
||||
}
|
||||
if !opts.IO.CanPrompt() && !opts.Confirmed {
|
||||
return cmdutil.FlagErrorf("could not prompt: confirmation with prompt or --confirm flag required")
|
||||
}
|
||||
|
|
@ -60,8 +63,15 @@ func deleteRun(opts *DeleteOptions) error {
|
|||
}
|
||||
apiClient := api.NewClientFromHTTP(httpClient)
|
||||
|
||||
repoSelector := opts.RepoArg
|
||||
var toDelete ghrepo.Interface
|
||||
repoSelector := opts.RepoArg
|
||||
if repoSelector == "" {
|
||||
currRepo, err := opts.BaseRepo()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
repoSelector = ghrepo.FullName(currRepo)
|
||||
}
|
||||
|
||||
if !strings.Contains(repoSelector, "/") {
|
||||
currentUser, err := api.CurrentLoginName(apiClient, ghinstance.Default())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue