| 120 | } |
| 121 | |
| 122 | func editRun(opts *EditOptions) error { |
| 123 | repo, err := opts.BaseRepo() |
| 124 | if err != nil { |
| 125 | return err |
| 126 | } |
| 127 | |
| 128 | c, err := opts.Client() |
| 129 | if err != nil { |
| 130 | return err |
| 131 | } |
| 132 | |
| 133 | opts.IO.StartProgressIndicator() |
| 134 | discussion, err := c.GetByNumber(repo, opts.DiscussionNumber) |
| 135 | opts.IO.StopProgressIndicator() |
| 136 | if err != nil { |
| 137 | return err |
| 138 | } |
| 139 | |
| 140 | input := client.UpdateDiscussionInput{ |
| 141 | DiscussionID: discussion.ID, |
| 142 | } |
| 143 | |
| 144 | if opts.Interactive { |
| 145 | changed, err := promptEdit(opts, discussion, c, repo, &input) |
| 146 | if err != nil { |
| 147 | return err |
| 148 | } |
| 149 | |
| 150 | if !changed { |
| 151 | return cmdutil.CancelError |
| 152 | } |
| 153 | } else { |
| 154 | if opts.TitleProvided { |
| 155 | if strings.TrimSpace(opts.Title) == "" { |
| 156 | return cmdutil.FlagErrorf("title cannot be blank") |
| 157 | } |
| 158 | input.Title = &opts.Title |
| 159 | } |
| 160 | if opts.BodyProvided { |
| 161 | if opts.BodyFile != "" { |
| 162 | bodyBytes, err := cmdutil.ReadFile(opts.BodyFile, opts.IO.In) |
| 163 | if err != nil { |
| 164 | return err |
| 165 | } |
| 166 | opts.Body = string(bodyBytes) |
| 167 | } |
| 168 | input.Body = &opts.Body |
| 169 | } |
| 170 | if opts.CategoryProvided { |
| 171 | opts.IO.StartProgressIndicator() |
| 172 | categories, err := c.ListCategories(repo) |
| 173 | opts.IO.StopProgressIndicator() |
| 174 | if err != nil { |
| 175 | return err |
| 176 | } |
| 177 | cat, err := shared.MatchCategory(opts.Category, categories) |
| 178 | if err != nil { |
| 179 | return err |