1
0
mirror of https://gitea.com/gitea/tea.git synced 2024-11-03 04:27:21 -05:00

Add repos rm/delete command (#609)

This fixes https://gitea.com/gitea/tea/issues/239

Co-authored-by: techknowlogick <techknowlogick@gitea.com>
Reviewed-on: https://gitea.com/gitea/tea/pulls/609
Co-authored-by: Dan Čermák <dcermak@suse.com>
Co-committed-by: Dan Čermák <dcermak@suse.com>
This commit is contained in:
Dan Čermák 2024-07-26 16:18:58 +00:00 committed by techknowlogick
parent 4c0cef090d
commit 723b0553c5
3 changed files with 100 additions and 0 deletions

View File

@ -29,6 +29,7 @@ var CmdRepos = cli.Command{
&repos.CmdRepoCreateFromTemplate, &repos.CmdRepoCreateFromTemplate,
&repos.CmdRepoFork, &repos.CmdRepoFork,
&repos.CmdRepoMigrate, &repos.CmdRepoMigrate,
&repos.CmdRepoRm,
}, },
Flags: repos.CmdReposListFlags, Flags: repos.CmdReposListFlags,
} }

85
cmd/repos/delete.go Normal file
View File

@ -0,0 +1,85 @@
// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package repos
import (
"fmt"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"github.com/AlecAivazis/survey/v2"
"github.com/urfave/cli/v2"
)
// CmdRepoRm represents a sub command of repos to delete an existing repo
var CmdRepoRm = cli.Command{
Name: "delete",
Aliases: []string{"rm"},
Usage: "Delete an existing repository",
Description: "Removes a repository from Create a repository from an existing repo",
ArgsUsage: " ", // command does not accept arguments
Action: runRepoDelete,
Flags: append([]cli.Flag{
&cli.StringFlag{
Name: "name",
Aliases: []string{""},
Required: true,
Usage: "name of the repo",
},
&cli.StringFlag{
Name: "owner",
Aliases: []string{"O"},
Required: false,
Usage: "owner of the repo",
},
&cli.BoolFlag{
Name: "force",
Aliases: []string{"f"},
Required: false,
Value: false,
Usage: "Force the deletion and don't ask for confirmation",
},
}, flags.LoginOutputFlags...),
}
func runRepoDelete(cmd *cli.Context) error {
ctx := context.InitCommand(cmd)
client := ctx.Login.Client()
var owner string
if ctx.IsSet("owner") {
owner = ctx.String("owner")
} else {
owner = ctx.Login.User
}
repoName := ctx.String("name")
repoSlug := fmt.Sprintf("%s/%s", owner, repoName)
if !ctx.Bool("force") {
var enteredRepoSlug string
promptRepoName := &survey.Input{
Message: fmt.Sprintf("Confirm the deletion of the repository '%s' by typing its name: ", repoSlug),
}
if err := survey.AskOne(promptRepoName, &enteredRepoSlug, survey.WithValidator(survey.Required)); err != nil {
return err
}
if enteredRepoSlug != repoSlug {
return fmt.Errorf("Entered wrong repository name '%s', expected '%s'", enteredRepoSlug, repoSlug)
}
}
_, err := client.DeleteRepo(owner, repoName)
if err != nil {
return err
}
fmt.Printf("Successfully deleted %s/%s\n", owner, repoName)
return nil
}

View File

@ -1173,6 +1173,20 @@ Migrate a repository
**--wiki**: Copy the wiki **--wiki**: Copy the wiki
### delete, rm
Delete an existing repository
**--force, -f**: Force the deletion and don't ask for confirmation
**--login, -l**="": Use a different Gitea Login. Optional
**--name, -**="": name of the repo
**--output, -o**="": Output format. (simple, table, csv, tsv, yaml, json)
**--owner, -O**="": owner of the repo
## branches, branch, b ## branches, branch, b
Consult branches Consult branches