1 /* Copyright 2012-present Facebook, Inc. 2 * Licensed under the Apache License, Version 2.0 */ 3 #pragma once 4 5 enum argtype { 6 OPT_NONE, 7 REQ_STRING, 8 REQ_INT, 9 }; 10 11 struct watchman_getopt { 12 /* name of long option: --optname */ 13 const char *optname; 14 /* if non-zero, short option character */ 15 int shortopt; 16 /* help text shown in the usage information */ 17 const char *helptext; 18 /* whether we accept an argument */ 19 enum argtype argtype; 20 /* if an argument was provided, *val will be set to 21 * point to the option value. 22 * Because we only update the option if one was provided 23 * by the user, you can safely pre-initialize the val 24 * pointer to your choice of default. 25 * */ 26 void *val; 27 28 /* if argtype != OPT_NONE, this is the label used to 29 * refer to the argument in the help text. If left 30 * blank, we'll use the string "ARG" as a generic 31 * alternative */ 32 const char *arglabel; 33 34 // Whether this option should be passed to the child 35 // when running under the gimli monitor 36 int is_daemon; 37 #define IS_DAEMON 1 38 #define NOT_DAEMON 0 39 }; 40 41 bool w_getopt( 42 struct watchman_getopt* opts, 43 int* argcp, 44 char*** argvp, 45 char*** daemon_argv); 46 void usage(struct watchman_getopt* opts, FILE* where); 47 void print_command_list_for_help(FILE* where); 48