Commit 90d3cc6c by Edward Thomson

cli: common options

parent 005bccea
...@@ -24,9 +24,7 @@ static int display = DISPLAY_CONTENT; ...@@ -24,9 +24,7 @@ static int display = DISPLAY_CONTENT;
static char *type_name, *object_spec; static char *type_name, *object_spec;
static const cli_opt_spec opts[] = { static const cli_opt_spec opts[] = {
{ CLI_OPT_TYPE_SWITCH, "help", 0, &show_help, 1, CLI_COMMON_OPT,
CLI_OPT_USAGE_HIDDEN | CLI_OPT_USAGE_STOP_PARSING, NULL,
"display help about the " COMMAND_NAME " command" },
{ CLI_OPT_TYPE_SWITCH, NULL, 't', &display, DISPLAY_TYPE, { CLI_OPT_TYPE_SWITCH, NULL, 't', &display, DISPLAY_TYPE,
CLI_OPT_USAGE_REQUIRED, NULL, "display the type of the object" }, CLI_OPT_USAGE_REQUIRED, NULL, "display the type of the object" },
......
...@@ -24,9 +24,7 @@ static bool local_path_exists; ...@@ -24,9 +24,7 @@ static bool local_path_exists;
static cli_progress progress = CLI_PROGRESS_INIT; static cli_progress progress = CLI_PROGRESS_INIT;
static const cli_opt_spec opts[] = { static const cli_opt_spec opts[] = {
{ CLI_OPT_TYPE_SWITCH, "help", 0, &show_help, 1, CLI_COMMON_OPT,
CLI_OPT_USAGE_HIDDEN | CLI_OPT_USAGE_STOP_PARSING, NULL,
"display help about the " COMMAND_NAME " command" },
{ CLI_OPT_TYPE_SWITCH, "quiet", 'q', &quiet, 1, { CLI_OPT_TYPE_SWITCH, "quiet", 'q', &quiet, 1,
CLI_OPT_USAGE_DEFAULT, NULL, "display the type of the object" }, CLI_OPT_USAGE_DEFAULT, NULL, "display the type of the object" },
......
...@@ -25,20 +25,8 @@ static int show_help; ...@@ -25,20 +25,8 @@ static int show_help;
static int null_separator; static int null_separator;
static char *name; static char *name;
#define CLI_COMMON_OPT_HELP \
CLI_OPT_TYPE_SWITCH, "help", 0, &show_help, 1, \
CLI_OPT_USAGE_HIDDEN | CLI_OPT_USAGE_STOP_PARSING
#define CLI_COMMON_OPT_CONFIG \
CLI_OPT_TYPE_VALUE, NULL, 'c', NULL, 0, \
CLI_OPT_USAGE_HIDDEN
#define CLI_COMMON_OPT_CONFIG_ENV \
CLI_OPT_TYPE_VALUE, "config-env", 0, NULL, 0, \
CLI_OPT_USAGE_HIDDEN
static const cli_opt_spec opts[] = { static const cli_opt_spec opts[] = {
{ CLI_COMMON_OPT_HELP }, CLI_COMMON_OPT, \
{ CLI_COMMON_OPT_CONFIG },
{ CLI_COMMON_OPT_CONFIG_ENV },
{ CLI_OPT_TYPE_SWITCH, "null", 'z', &null_separator, 1, { CLI_OPT_TYPE_SWITCH, "null", 'z', &null_separator, 1,
0, NULL, "use NUL as a separator" }, 0, NULL, "use NUL as a separator" },
......
...@@ -19,9 +19,7 @@ static int write_object, read_stdin, literally; ...@@ -19,9 +19,7 @@ static int write_object, read_stdin, literally;
static char **filenames; static char **filenames;
static const cli_opt_spec opts[] = { static const cli_opt_spec opts[] = {
{ CLI_OPT_TYPE_SWITCH, "help", 0, &show_help, 1, CLI_COMMON_OPT,
CLI_OPT_USAGE_HIDDEN | CLI_OPT_USAGE_STOP_PARSING, NULL,
"display help about the " COMMAND_NAME " command" },
{ CLI_OPT_TYPE_VALUE, NULL, 't', &type_name, 0, { CLI_OPT_TYPE_VALUE, NULL, 't', &type_name, 0,
CLI_OPT_USAGE_DEFAULT, "type", "the type of object to hash (default: \"blob\")" }, CLI_OPT_USAGE_DEFAULT, "type", "the type of object to hash (default: \"blob\")" },
......
...@@ -16,8 +16,8 @@ static char *command; ...@@ -16,8 +16,8 @@ static char *command;
static int show_help; static int show_help;
static const cli_opt_spec opts[] = { static const cli_opt_spec opts[] = {
{ CLI_OPT_TYPE_SWITCH, "help", 0, &show_help, 1, CLI_COMMON_OPT,
CLI_OPT_USAGE_HIDDEN, NULL, "display help about the help command" },
{ CLI_OPT_TYPE_ARG, "command", 0, &command, 0, { CLI_OPT_TYPE_ARG, "command", 0, &command, 0,
CLI_OPT_USAGE_DEFAULT, "command", "the command to show help for" }, CLI_OPT_USAGE_DEFAULT, "command", "the command to show help for" },
{ 0 }, { 0 },
......
...@@ -44,4 +44,23 @@ extern int cli_repository_open( ...@@ -44,4 +44,23 @@ extern int cli_repository_open(
git_repository **out, git_repository **out,
cli_repository_open_options *opts); cli_repository_open_options *opts);
/*
* Common command arguments.
*/
#define CLI_COMMON_OPT_HELP \
CLI_OPT_TYPE_SWITCH, "help", 0, &show_help, 1, \
CLI_OPT_USAGE_HIDDEN | CLI_OPT_USAGE_STOP_PARSING
#define CLI_COMMON_OPT_CONFIG \
CLI_OPT_TYPE_VALUE, NULL, 'c', NULL, 0, \
CLI_OPT_USAGE_HIDDEN
#define CLI_COMMON_OPT_CONFIG_ENV \
CLI_OPT_TYPE_VALUE, "config-env", 0, NULL, 0, \
CLI_OPT_USAGE_HIDDEN
#define CLI_COMMON_OPT \
{ CLI_COMMON_OPT_HELP }, \
{ CLI_COMMON_OPT_CONFIG }, \
{ CLI_COMMON_OPT_CONFIG_ENV }
#endif /* CLI_common_h__ */ #endif /* CLI_common_h__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment