mirror of https://gitea.com/gitea/tea.git
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:
parent
4c0cef090d
commit
723b0553c5
|
@ -29,6 +29,7 @@ var CmdRepos = cli.Command{
|
|||
&repos.CmdRepoCreateFromTemplate,
|
||||
&repos.CmdRepoFork,
|
||||
&repos.CmdRepoMigrate,
|
||||
&repos.CmdRepoRm,
|
||||
},
|
||||
Flags: repos.CmdReposListFlags,
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
14
docs/CLI.md
14
docs/CLI.md
|
@ -1173,6 +1173,20 @@ Migrate a repository
|
|||
|
||||
**--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
|
||||
|
||||
Consult branches
|
||||
|
|
Loading…
Reference in New Issue