diff options
author | Andres Freund <andres@anarazel.de> | 2014-09-09 22:19:14 +0200 |
---|---|---|
committer | Andres Freund <andres@anarazel.de> | 2014-09-10 00:08:56 +0200 |
commit | 07c8651dd91d5aea38bee268acb582674ca4b5ea (patch) | |
tree | 806433b72903df9f2081d563454ae610260d09f0 /src/bin/psql/startup.c | |
parent | 0709b7ee72e4bc71ad07b7120acd117265ab51d0 (diff) |
Add new psql help topics, accessible to both --help and \?.
Add --help=<topic> for the commandline, and \? <topic> as a backslash
command, to show more help than the invocations without parameters
do. "commands", "variables" and "options" currently exist as help
topics describing, respectively, backslash commands, psql variables,
and commandline switches. Without parameters the help commands show
their previous topic.
Some further wordsmithing or extending of the added help content might
be needed; but there seems little benefit delaying the overall feature
further.
Author: Pavel Stehule, editorialized by many
Reviewed-By: Andres Freund, Petr Jelinek, Fujii Masao, MauMau, Abhijit
Menon-Sen and Erik Rijkers.
Discussion: CAFj8pRDVGuC-nXBfe2CK8vpyzd2Dsr9GVpbrATAnZO=2YQ0s2Q@mail.gmail.com,
CAFj8pRA54AbTv2RXDTRxiAd8hy8wxmoVLqhJDRCwEnhdd7OUkw@mail.gmail.com
Diffstat (limited to 'src/bin/psql/startup.c')
-rw-r--r-- | src/bin/psql/startup.c | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c index 5a397e8d550..b879d0c35d3 100644 --- a/src/bin/psql/startup.c +++ b/src/bin/psql/startup.c @@ -77,6 +77,8 @@ static void process_psqlrc_file(char *filename); static void showVersion(void); static void EstablishVariableSpace(void); +#define NOPAGER 0 + /* * * main @@ -95,9 +97,9 @@ main(int argc, char *argv[]) if (argc > 1) { - if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0) + if ((strcmp(argv[1], "-?") == 0) || (argc == 2 && (strcmp(argv[1], "--help") == 0))) { - usage(); + usage(NOPAGER); exit(EXIT_SUCCESS); } if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0) @@ -383,7 +385,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options) {"password", no_argument, NULL, 'W'}, {"expanded", no_argument, NULL, 'x'}, {"no-psqlrc", no_argument, NULL, 'X'}, - {"help", no_argument, NULL, '?'}, + {"help", optional_argument, NULL, 1}, {NULL, 0, NULL, 0} }; @@ -557,20 +559,31 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options) break; case '?': /* Actual help option given */ - if (strcmp(argv[optind - 1], "--help") == 0 || strcmp(argv[optind - 1], "-?") == 0) + if (strcmp(argv[optind - 1], "-?") == 0) { - usage(); + usage(NOPAGER); exit(EXIT_SUCCESS); } /* unknown option reported by getopt */ else + goto unknown_option; + break; + case 1: { - fprintf(stderr, _("Try \"%s --help\" for more information.\n"), - pset.progname); - exit(EXIT_FAILURE); + if (!optarg || strcmp(optarg, "options") == 0) + usage(NOPAGER); + else if (optarg && strcmp(optarg, "commands") == 0) + slashUsage(NOPAGER); + else if (optarg && strcmp(optarg, "variables") == 0) + helpVariables(NOPAGER); + else + goto unknown_option; + + exit(EXIT_SUCCESS); } break; default: + unknown_option: fprintf(stderr, _("Try \"%s --help\" for more information.\n"), pset.progname); exit(EXIT_FAILURE); |