summaryrefslogtreecommitdiff
path: root/help.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2017-05-30 05:17:42 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-06-05 02:43:33 (GMT)
commitb48cbfc5e6112952bc3be4dea0208bc5e1f331eb (patch)
tree7db0b1d288cf804cd2b67eca487c2bb94e1f8104 /help.c
parent5a88f97cff0f269f8b2069b17c9da05ee66c98bb (diff)
downloadgit-b48cbfc5e6112952bc3be4dea0208bc5e1f331eb.zip
git-b48cbfc5e6112952bc3be4dea0208bc5e1f331eb.tar.gz
git-b48cbfc5e6112952bc3be4dea0208bc5e1f331eb.tar.bz2
version: convert to parse-options
The "git version" command didn't traditionally accept any options, and in fact ignores any you give it. When we added simple option parsing for "--build-options" in 6b9c38e14, we didn't improve this; we just loop over the arguments and pick out the one we recognize. Instead, let's move to a real parsing loop, complain about nonsense options, and recognize conventions like "-h". Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'help.c')
-rw-r--r--help.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/help.c b/help.c
index bc6cd19..1064363 100644
--- a/help.c
+++ b/help.c
@@ -8,6 +8,7 @@
#include "column.h"
#include "version.h"
#include "refs.h"
+#include "parse-options.h"
void add_cmdname(struct cmdnames *cmds, const char *name, int len)
{
@@ -424,16 +425,30 @@ const char *help_unknown_cmd(const char *cmd)
int cmd_version(int argc, const char **argv, const char *prefix)
{
+ int build_options = 0;
+ const char * const usage[] = {
+ N_("git version [<options>]"),
+ NULL
+ };
+ struct option options[] = {
+ OPT_BOOL(0, "build-options", &build_options,
+ "also print build options"),
+ OPT_END()
+ };
+
+ argc = parse_options(argc, argv, prefix, options, usage, 0);
+
/*
* The format of this string should be kept stable for compatibility
* with external projects that rely on the output of "git version".
+ *
+ * Always show the version, even if other options are given.
*/
printf("git version %s\n", git_version_string);
- while (*++argv) {
- if (!strcmp(*argv, "--build-options")) {
- printf("sizeof-long: %d\n", (int)sizeof(long));
- /* NEEDSWORK: also save and output GIT-BUILD_OPTIONS? */
- }
+
+ if (build_options) {
+ printf("sizeof-long: %d\n", (int)sizeof(long));
+ /* NEEDSWORK: also save and output GIT-BUILD_OPTIONS? */
}
return 0;
}