MCPcopy
hub / github.com/cli/cli / NewCmdDelete

Function NewCmdDelete

pkg/cmd/project/delete/delete.go:35–77  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(config deleteConfig) error)

Source from the content-addressed store, hash-verified

33}
34
35func NewCmdDelete(f *cmdutil.Factory, runF func(config deleteConfig) error) *cobra.Command {
36 opts := deleteOpts{}
37 deleteCmd := &cobra.Command{
38 Short: "Delete a project",
39 Use: "delete [<number>]",
40 Example: heredoc.Doc(`
41 # Delete the current user's project "1"
42 $ gh project delete 1 --owner "@me"
43 `),
44 Args: cobra.MaximumNArgs(1),
45 RunE: func(cmd *cobra.Command, args []string) error {
46 client, err := client.New(f)
47 if err != nil {
48 return err
49 }
50
51 if len(args) == 1 {
52 num, err := strconv.ParseInt(args[0], 10, 32)
53 if err != nil {
54 return cmdutil.FlagErrorf("invalid number: %v", args[0])
55 }
56 opts.number = int32(num)
57 }
58
59 config := deleteConfig{
60 client: client,
61 opts: opts,
62 io: f.IOStreams,
63 }
64
65 // allow testing of the command without actually running it
66 if runF != nil {
67 return runF(config)
68 }
69 return runDelete(config)
70 },
71 }
72
73 deleteCmd.Flags().StringVar(&opts.owner, "owner", "", "Login of the owner. Use \"@me\" for the current user.")
74 cmdutil.AddFormatFlags(deleteCmd, &opts.exporter)
75
76 return deleteCmd
77}
78
79func runDelete(config deleteConfig) error {
80 canPrompt := config.io.CanPrompt()

Callers 1

TestNewCmdDeleteFunction · 0.70

Calls 4

NewFunction · 0.92
FlagErrorfFunction · 0.92
AddFormatFlagsFunction · 0.92
runDeleteFunction · 0.70

Tested by 1

TestNewCmdDeleteFunction · 0.56