| 96 | } |
| 97 | |
| 98 | func createRun(opts *CreateOptions) error { |
| 99 | repo, err := opts.BaseRepo() |
| 100 | if err != nil { |
| 101 | return err |
| 102 | } |
| 103 | |
| 104 | c, err := opts.Client() |
| 105 | if err != nil { |
| 106 | return err |
| 107 | } |
| 108 | |
| 109 | opts.IO.StartProgressIndicator() |
| 110 | categories, err := c.ListCategories(repo) |
| 111 | opts.IO.StopProgressIndicator() |
| 112 | if err != nil { |
| 113 | return err |
| 114 | } |
| 115 | |
| 116 | if opts.Title == "" { |
| 117 | opts.Title, err = opts.Prompter.Input("Discussion title", "") |
| 118 | if err != nil { |
| 119 | return err |
| 120 | } |
| 121 | if strings.TrimSpace(opts.Title) == "" { |
| 122 | return fmt.Errorf("title cannot be blank") |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | var category *client.DiscussionCategory |
| 127 | if opts.Category != "" { |
| 128 | category, err = shared.MatchCategory(opts.Category, categories) |
| 129 | if err != nil { |
| 130 | return err |
| 131 | } |
| 132 | } else { |
| 133 | names := make([]string, len(categories)) |
| 134 | for i, cat := range categories { |
| 135 | names[i] = cat.Name |
| 136 | } |
| 137 | idx, err := opts.Prompter.Select("Discussion category", "", names) |
| 138 | if err != nil { |
| 139 | return err |
| 140 | } |
| 141 | category = &categories[idx] |
| 142 | } |
| 143 | |
| 144 | if opts.BodyFile != "" { |
| 145 | bodyBytes, err := cmdutil.ReadFile(opts.BodyFile, opts.IO.In) |
| 146 | if err != nil { |
| 147 | return err |
| 148 | } |
| 149 | opts.Body = string(bodyBytes) |
| 150 | } |
| 151 | |
| 152 | if opts.Body == "" { |
| 153 | opts.Body, err = opts.Prompter.MarkdownEditor("Discussion body", "", false) |
| 154 | if err != nil { |
| 155 | return err |