MCPcopy Index your code
hub / github.com/cli/cli / NewCmdEdit

Function NewCmdEdit

pkg/cmd/release/edit/edit.go:32–90  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(*EditOptions) error)

Source from the content-addressed store, hash-verified

30}
31
32func NewCmdEdit(f *cmdutil.Factory, runF func(*EditOptions) error) *cobra.Command {
33 opts := &EditOptions{
34 IO: f.IOStreams,
35 HttpClient: f.HttpClient,
36 }
37
38 var notesFile string
39
40 cmd := &cobra.Command{
41 DisableFlagsInUseLine: true,
42
43 Use: "edit <tag>",
44 Short: "Edit a release",
45 Example: heredoc.Doc(`
46 # Publish a release that was previously a draft
47 $ gh release edit v1.0 --draft=false
48
49 # Update the release notes from the content of a file
50 $ gh release edit v1.0 --notes-file /path/to/release_notes.md
51 `),
52 Args: cobra.ExactArgs(1),
53 RunE: func(cmd *cobra.Command, args []string) error {
54 opts.BaseRepo = f.BaseRepo
55
56 if cmd.Flags().NFlag() == 0 {
57 return cmdutil.FlagErrorf("use flags to specify properties to edit")
58 }
59
60 if notesFile != "" {
61 b, err := cmdutil.ReadFile(notesFile, opts.IO.In)
62 if err != nil {
63 return err
64 }
65 body := string(b)
66 opts.Body = &body
67 }
68
69 if runF != nil {
70 return runF(opts)
71 }
72 return editRun(args[0], opts)
73 },
74 }
75
76 cmdutil.NilBoolFlag(cmd, &opts.Draft, "draft", "", "Save the release as a draft instead of publishing it")
77 cmdutil.NilBoolFlag(cmd, &opts.Prerelease, "prerelease", "", "Mark the release as a prerelease")
78 cmdutil.NilBoolFlag(cmd, &opts.IsLatest, "latest", "", "Explicitly mark the release as \"Latest\"")
79 cmdutil.NilStringFlag(cmd, &opts.Body, "notes", "n", "Release notes")
80 cmdutil.NilStringFlag(cmd, &opts.Name, "title", "t", "Release title")
81 cmdutil.NilStringFlag(cmd, &opts.DiscussionCategory, "discussion-category", "", "Start a discussion in the specified category when publishing a draft")
82 cmd.Flags().StringVar(&opts.Target, "target", "", "Target `branch` or full commit SHA (default [main branch])")
83 cmd.Flags().StringVar(&opts.TagName, "tag", "", "The name of the tag")
84 cmd.Flags().StringVarP(&notesFile, "notes-file", "F", "", "Read release notes from `file` (use \"-\" to read from standard input)")
85 cmd.Flags().BoolVar(&opts.VerifyTag, "verify-tag", false, "Abort in case the git tag doesn't already exist in the remote repository")
86
87 _ = cmdutil.RegisterBranchCompletionFlags(f.GitClient, cmd, "target")
88
89 return cmd

Callers 1

Test_NewCmdEditFunction · 0.70

Calls 6

FlagErrorfFunction · 0.92
ReadFileFunction · 0.92
NilBoolFlagFunction · 0.92
NilStringFlagFunction · 0.92
editRunFunction · 0.70

Tested by 1

Test_NewCmdEditFunction · 0.56