|
1 | 1 | #include "git-compat-util.h" |
2 | 2 | #include "parse-options.h" |
3 | | -#include "strbuf.h" |
4 | 3 |
|
5 | 4 | #define OPT_SHORT 1 |
6 | 5 | #define OPT_UNSET 2 |
@@ -172,59 +171,57 @@ int parse_options(int argc, const char **argv, const struct option *options, |
172 | 171 | void usage_with_options(const char * const *usagestr, |
173 | 172 | const struct option *opts) |
174 | 173 | { |
175 | | - struct strbuf sb; |
176 | | - |
177 | | - strbuf_init(&sb, 4096); |
178 | | - strbuf_addstr(&sb, *usagestr); |
179 | | - strbuf_addch(&sb, '\n'); |
180 | | - while (*++usagestr) |
181 | | - strbuf_addf(&sb, " %s\n", *usagestr); |
| 174 | + fprintf(stderr, "usage: %s\n", *usagestr++); |
| 175 | + while (*usagestr && **usagestr) |
| 176 | + fprintf(stderr, " or: %s\n", *usagestr++); |
| 177 | + while (*usagestr) |
| 178 | + fprintf(stderr, " %s\n", *usagestr++); |
182 | 179 |
|
183 | 180 | if (opts->type != OPTION_GROUP) |
184 | | - strbuf_addch(&sb, '\n'); |
| 181 | + fputc('\n', stderr); |
185 | 182 |
|
186 | 183 | for (; opts->type != OPTION_END; opts++) { |
187 | 184 | size_t pos; |
188 | 185 | int pad; |
189 | 186 |
|
190 | 187 | if (opts->type == OPTION_GROUP) { |
191 | | - strbuf_addch(&sb, '\n'); |
| 188 | + fputc('\n', stderr); |
192 | 189 | if (*opts->help) |
193 | | - strbuf_addf(&sb, "%s\n", opts->help); |
| 190 | + fprintf(stderr, "%s\n", opts->help); |
194 | 191 | continue; |
195 | 192 | } |
196 | 193 |
|
197 | | - pos = sb.len; |
198 | | - strbuf_addstr(&sb, " "); |
| 194 | + pos = fprintf(stderr, " "); |
199 | 195 | if (opts->short_name) |
200 | | - strbuf_addf(&sb, "-%c", opts->short_name); |
| 196 | + pos += fprintf(stderr, "-%c", opts->short_name); |
201 | 197 | if (opts->long_name && opts->short_name) |
202 | | - strbuf_addstr(&sb, ", "); |
| 198 | + pos += fprintf(stderr, ", "); |
203 | 199 | if (opts->long_name) |
204 | | - strbuf_addf(&sb, "--%s", opts->long_name); |
| 200 | + pos += fprintf(stderr, "--%s", opts->long_name); |
205 | 201 |
|
206 | 202 | switch (opts->type) { |
207 | 203 | case OPTION_INTEGER: |
208 | | - strbuf_addstr(&sb, " <n>"); |
| 204 | + pos += fprintf(stderr, " <n>"); |
209 | 205 | break; |
210 | 206 | case OPTION_STRING: |
211 | 207 | if (opts->argh) |
212 | | - strbuf_addf(&sb, " <%s>", opts->argh); |
| 208 | + pos += fprintf(stderr, " <%s>", opts->argh); |
213 | 209 | else |
214 | | - strbuf_addstr(&sb, " ..."); |
| 210 | + pos += fprintf(stderr, " ..."); |
215 | 211 | break; |
216 | 212 | default: |
217 | 213 | break; |
218 | 214 | } |
219 | 215 |
|
220 | | - pad = sb.len - pos; |
221 | | - if (pad <= USAGE_OPTS_WIDTH) |
222 | | - pad = USAGE_OPTS_WIDTH - pad; |
| 216 | + if (pos <= USAGE_OPTS_WIDTH) |
| 217 | + pad = USAGE_OPTS_WIDTH - pos; |
223 | 218 | else { |
224 | | - strbuf_addch(&sb, '\n'); |
| 219 | + fputc('\n', stderr); |
225 | 220 | pad = USAGE_OPTS_WIDTH; |
226 | 221 | } |
227 | | - strbuf_addf(&sb, "%*s%s\n", pad + USAGE_GAP, "", opts->help); |
| 222 | + fprintf(stderr, "%*s%s\n", pad + USAGE_GAP, "", opts->help); |
228 | 223 | } |
229 | | - usage(sb.buf); |
| 224 | + fputc('\n', stderr); |
| 225 | + |
| 226 | + exit(129); |
230 | 227 | } |
0 commit comments