package cmd import ( "fmt" "forgejo.zerova.net/public/fgj-sid/internal/api" "forgejo.zerova.net/public/fgj-sid/internal/config" "github.com/spf13/cobra" ) var repoDeleteCmd = &cobra.Command{ Use: "delete [owner/name]", Aliases: []string{"rm"}, Short: "Delete a repository", Long: `Delete a repository. This is irreversible and removes all issues, PRs, wikis, and release artifacts. For safety, you must either pass -y/--yes, or type the full owner/name string when prompted.`, Example: ` # Delete a repository (prompted confirmation) fgj repo delete owner/name # Delete without confirmation (scripts) fgj repo delete owner/name --yes`, Args: cobra.MaximumNArgs(1), RunE: runRepoDelete, } func init() { repoCmd.AddCommand(repoDeleteCmd) repoDeleteCmd.Flags().BoolP("yes", "y", false, "Skip the type-to-confirm prompt") } func runRepoDelete(cmd *cobra.Command, args []string) error { var target string if len(args) == 1 { target = args[0] } owner, name, err := parseRepo(target) if err != nil { return err } cfg, err := config.Load() if err != nil { return err } client, err := api.NewClientFromConfig(cfg, "", getDetectedHost(), getCwd()) if err != nil { return err } slug := fmt.Sprintf("%s/%s", owner, name) skipConfirm, _ := cmd.Flags().GetBool("yes") if !skipConfirm { if !ios.IsStdinTTY() { return fmt.Errorf("refusing to delete %s without a TTY; pass --yes to confirm non-interactively", slug) } prompt := fmt.Sprintf("Type the full repo slug to confirm deletion (%s): ", slug) answer, err := promptLine(prompt) if err != nil { return err } if answer != slug { fmt.Fprintln(ios.ErrOut, "Confirmation mismatch; aborting.") return nil } } if _, err := client.DeleteRepo(owner, name); err != nil { return fmt.Errorf("failed to delete %s: %w", slug, err) } cs := ios.ColorScheme() fmt.Fprintf(ios.Out, "%s Deleted %s\n", cs.SuccessIcon(), slug) return nil }