Skip to content

Commit

Permalink
scalar: implement the version command
Browse files Browse the repository at this point in the history
The .NET version of Scalar has a `version` command. This was necessary
because it was versioned independently of Git.

Since Scalar is now tightly coupled with Git, it does not make sense for
them to show different versions. Therefore, it shows the same output as
`git versions`. For backwards-compatibility with the .NET version,
`scalar version` prints to `stderr`, though (`git version` prints to
`stdout` instead).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
dscho committed Jun 7, 2021
1 parent 6787f74 commit 13fab8f
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions contrib/scalar/scalar.c
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,34 @@ static int cmd_delete(int argc, const char **argv)
return delete_enlistment();
}

static int cmd_version(int argc, const char **argv)
{
int verbose = 0, build_options = 0;
struct option options[] = {
OPT__VERBOSE(&verbose, N_("include Git version")),
OPT_BOOL(0, "build-options", &build_options,
N_("include Git's build options")),
OPT_END(),
};
const char * const usage[] = {
N_("scalar verbose [-v | --verbose] [--build-options]"),
NULL
};
struct strbuf buf = STRBUF_INIT;

argc = parse_options(argc, argv, NULL, options,
usage, 0);

if (argc != 0)
usage_with_options(usage, options);

get_version_info(&buf, build_options);
fprintf(stderr, "%s\n", buf.buf);
strbuf_release(&buf);

return 0;
}

struct {
const char *name;
int (*fn)(int, const char **);
Expand All @@ -1080,6 +1108,7 @@ struct {
{ "reconfigure", cmd_reconfigure },
{ "diagnose", cmd_diagnose },
{ "delete", cmd_delete },
{ "version", cmd_version },
{ NULL, NULL},
};

Expand Down

0 comments on commit 13fab8f

Please sign in to comment.