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

64 lines
1.2 KiB
Go
Raw Normal View History

2019-08-14 12:06:45 +00:00
package main
import (
"fmt"
"strings"
"github.com/spf13/cobra"
)
// destroyCmd represents the destroy command
var destroyCmd = &cobra.Command{
2016-07-28 11:56:10 +00:00
Aliases: []string{"d", "delete", "rid"},
Use: "destroy [username repo-name | username/repo-name]",
Short: "Destroy a repo.",
2019-08-14 12:06:45 +00:00
Example: `
destroy ia tester-repo
destroy ia/tester-repo
2016-07-28 00:11:57 +00:00
`,
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)
}