gogs-cli/cmd/gogs/repo-destroy.go

64 lines
1.2 KiB
Go

package main
import (
"fmt"
"strings"
"github.com/spf13/cobra"
)
// destroyCmd represents the destroy command
var destroyCmd = &cobra.Command{
Aliases: []string{"d", "delete", "rid"},
Use: "destroy [username repo-name | username/repo-name]",
Short: "Destroy a repo.",
Example: `
destroy ia tester-repo
destroy ia/tester-repo
`,
Run: func(cmd *cobra.Command, args []string) {
var owner string
var repo string
// ia/testes || ia testes
if (len(args) == 0) || (len(args) > 2) {
fmt.Println("Please argue me [username/repo-name] or [username repo-name].")
return
}
// ia/testes
if len(args) == 1 {
slasher := strings.Split(args[0], "/")
if len(slasher) == 2 {
owner, repo = slasher[0], slasher[1]
} else {
fmt.Println("Please argue me [username/repo-name] or [username repo-name].")
return
}
}
// ia testes
if len(args) == 2 {
owner, repo = args[0], args[1]
}
if (owner == "") || (repo == "") {
fmt.Println("Please argue me [username/repo-name] or [username repo-name].")
return
}
err := GetClient().DeleteRepo(owner, repo)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("Deleted %v/%v.\n\n", owner, repo)
},
}
func init() {
repoCmd.AddCommand(destroyCmd)
}