commit - 0f84e4996c5a10d8ffca30998a7c99883e142e9e
commit + 6879ba4225a833ea466b3512329293abfd9bf33a
blob - e2b4927b8bb743bb45718b5c21b186f11b4f918a
blob + 7b77c62ca03d78d5a88d8053e2281321de9c2b84
--- got/got.c
+++ got/got.c
const char *cmd_alias;
};
-__dead static void usage(int);
+__dead static void usage(int, int);
__dead static void usage_init(void);
__dead static void usage_import(void);
__dead static void usage_clone(void);
};
static void
-list_commands(void)
+list_commands(FILE *fp)
{
int i;
- fprintf(stderr, "commands:");
+ fprintf(fp, "commands:");
for (i = 0; i < nitems(got_commands); i++) {
struct got_cmd *cmd = &got_commands[i];
- fprintf(stderr, " %s", cmd->cmd_name);
+ fprintf(fp, " %s", cmd->cmd_name);
}
- fputc('\n', stderr);
+ fputc('\n', fp);
}
int
Vflag = 1;
break;
default:
- usage(hflag);
+ usage(hflag, 1);
/* NOTREACHED */
}
}
if (Vflag) {
got_version_print_str();
- return 1;
+ return 0;
}
if (argc <= 0)
- usage(hflag);
+ usage(hflag, hflag ? 0 : 1);
signal(SIGINT, catch_sigint);
signal(SIGPIPE, catch_sigpipe);
}
fprintf(stderr, "%s: unknown command '%s'\n", getprogname(), argv[0]);
- list_commands();
+ list_commands(stderr);
return 1;
}
__dead static void
-usage(int hflag)
+usage(int hflag, int status)
{
- fprintf(stderr, "usage: %s [-h] [-V | --version] command [arg ...]\n",
+ FILE *fp = (status == 0) ? stdout : stderr;
+
+ fprintf(fp, "usage: %s [-h] [-V | --version] command [arg ...]\n",
getprogname());
if (hflag)
- list_commands();
- exit(1);
+ list_commands(fp);
+ exit(status);
}
static const struct got_error *
blob - 4d3c8ce6aa1ab5d45f4d36bede4d892708b96873
blob + a99744c546674ba7c12f31a138da72c698c6902d
--- tog/tog.c
+++ tog/tog.c
void (*cmd_usage)(void);
};
-__dead static void usage(int);
+__dead static void usage(int, int);
__dead static void usage_log(void);
__dead static void usage_diff(void);
__dead static void usage_blame(void);
}
static void
-list_commands(void)
+list_commands(FILE *fp)
{
int i;
- fprintf(stderr, "commands:");
+ fprintf(fp, "commands:");
for (i = 0; i < nitems(tog_commands); i++) {
struct tog_cmd *cmd = &tog_commands[i];
- fprintf(stderr, " %s", cmd->name);
+ fprintf(fp, " %s", cmd->name);
}
- fputc('\n', stderr);
+ fputc('\n', fp);
}
__dead static void
-usage(int hflag)
+usage(int hflag, int status)
{
- fprintf(stderr, "usage: %s [-h] [-V | --version] [command] "
- "[arg ...]\n", getprogname());
- if (hflag) {
- fprintf(stderr, "lazy usage: %s path\n", getprogname());
- list_commands();
+ FILE *fp = (status == 0) ? stdout : stderr;
+
+ fprintf(fp, "usage: %s [-h] [-V | --version] [command] [arg ...]\n",
+ getprogname());
+ if (hflag) {
+ fprintf(fp, "lazy usage: %s path\n", getprogname());
+ list_commands(fp);
}
- exit(1);
+ exit(status);
}
static char **
goto done;
fprintf(stderr, "%s: '%s' is no known command or path\n",
getprogname(), argv[0]);
- usage(1);
+ usage(1, 1);
/* not reached */
}
Vflag = 1;
break;
default:
- usage(hflag);
+ usage(hflag, 1);
/* NOTREACHED */
}
}
if (Vflag) {
got_version_print_str();
- return 1;
+ return 0;
}
if (argc == 0) {
if (hflag)
- usage(hflag);
+ usage(hflag, 0);
/* Build an argument vector which runs a default command. */
cmd = &tog_commands[0];
argc = 1;
if (cmd == NULL) {
if (argc != 1)
- usage(0);
+ usage(0, 1);
/* No command specified; try log with a path */
error = tog_log_with_path(argc, argv);
} else {