Пример #1
0
static void print_usage_and_exit(gpr_cmdline *cl, const char *argv0) {
  char *usage = gpr_cmdline_usage_string(cl, argv0);
  fprintf(stderr, "%s", usage);
  gpr_free(usage);
  gpr_cmdline_destroy(cl);
  exit(1);
}
Пример #2
0
static int print_usage_and_die(gpr_cmdline *cl) {
  char *usage = gpr_cmdline_usage_string(cl, cl->argv0);
  fprintf(stderr, "%s", usage);
  gpr_free(usage);
  if (!cl->survive_failure) {
    exit(1);
  }
  return 0;
}
Пример #3
0
static void test_usage(void) {
  gpr_cmdline *cl;
  char *usage;

  char *str = NULL;
  int x = 0;
  int flag = 2;

  cl = gpr_cmdline_create(NULL);
  gpr_cmdline_add_string(cl, "str", NULL, &str);
  gpr_cmdline_add_int(cl, "x", NULL, &x);
  gpr_cmdline_add_flag(cl, "flag", NULL, &flag);

  usage = gpr_cmdline_usage_string(cl, "test");
  GPR_ASSERT(0 == strcmp(usage,
    "Usage: test [--str=string] [--x=int] [--flag|--no-flag]\n"));
  gpr_free(usage);

  gpr_cmdline_destroy(cl);
}