summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2019-01-24 11:48:44 +0100
committerPatrick Steinhardt <ps@pks.im>2019-02-15 12:07:07 +0100
commit106998fce6e8cd57916f4f5b37f940eeafe297de (patch)
tree0a16a8166497934bf216a759d37d2586ee745d30 /examples
parentead10785dcd9e7599a52a0349a69c113c76e650d (diff)
downloadlibgit2-106998fce6e8cd57916f4f5b37f940eeafe297de.tar.gz
examples: print available commands if no args are given
Diffstat (limited to 'examples')
-rw-r--r--examples/lg2.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/examples/lg2.c b/examples/lg2.c
index 1f6fd8560..b3df02dbd 100644
--- a/examples/lg2.c
+++ b/examples/lg2.c
@@ -50,6 +50,17 @@ static int run_command(git_command_fn fn, git_repository *repo, struct args_info
return !!error;
}
+static int usage(const char *prog)
+{
+ size_t i;
+
+ fprintf(stderr, "usage: %s <cmd>...\n\nAvailable commands:\n\n", prog);
+ for (i = 0; i < ARRAY_SIZE(commands); i++)
+ fprintf(stderr, "\t%s\n", commands[i].name);
+
+ exit(EXIT_FAILURE);
+}
+
int main(int argc, char **argv)
{
struct args_info args = ARGS_INFO_INIT;
@@ -58,10 +69,8 @@ int main(int argc, char **argv)
int return_code = 1;
size_t i;
- if (argc < 2) {
- fprintf(stderr, "usage: %s <cmd> [repo]\n", argv[0]);
- exit(EXIT_FAILURE);
- }
+ if (argc < 2)
+ usage(argv[0]);
git_libgit2_init();
@@ -79,6 +88,9 @@ int main(int argc, char **argv)
}
}
+ if (args.pos == args.argc)
+ usage(argv[0]);
+
if (!git_dir)
git_dir = ".";