summaryrefslogtreecommitdiff
path: root/src/ostree/main.c
diff options
context:
space:
mode:
authorLuca BRUNO <luca.bruno@coreos.com>2021-12-20 10:00:02 +0000
committerLuca BRUNO <luca.bruno@coreos.com>2021-12-20 10:00:02 +0000
commit513b3c09a54af31ffd1b0eb9b3c47849816483be (patch)
treed8fc230e2dd16fb0e88f0d4789f951a74a9cd234 /src/ostree/main.c
parent365559eaa8126d60366b3f69585268dd89ce3a3a (diff)
downloadostree-513b3c09a54af31ffd1b0eb9b3c47849816483be.tar.gz
main: add support for CLI extensions via external binaries
This adds some logic to detect and dispatch unknown subcommands to extensions available in `$PATH`. Additional commands can be implemented by adding relevant `ostree-$verb` binaries to the system. As an example, if a `/usr/bin/ostree-extcommand` extension is provided, the execution of `ostree extcommand --help` will be dispatched to that as `ostree-extcommand extcommand --help`.
Diffstat (limited to 'src/ostree/main.c')
-rw-r--r--src/ostree/main.c25
1 files changed, 9 insertions, 16 deletions
diff --git a/src/ostree/main.c b/src/ostree/main.c
index 0e47ede3..7d17080c 100644
--- a/src/ostree/main.c
+++ b/src/ostree/main.c
@@ -26,7 +26,6 @@
#include <errno.h>
#include <string.h>
#include <unistd.h>
-#include <locale.h>
#include "ot-main.h"
#include "ot-builtins.h"
@@ -131,22 +130,16 @@ int
main (int argc,
char **argv)
{
- g_autoptr(GError) error = NULL;
- int ret;
+ g_assert (argc > 0);
- setlocale (LC_ALL, "");
-
- g_set_prgname (argv[0]);
-
- ret = ostree_run (argc, argv, commands, &error);
-
- if (error != NULL)
+ g_autofree gchar *ext_command = ostree_command_lookup_external (argc, argv, commands);
+ if (ext_command != NULL)
{
- g_printerr ("%s%serror:%s%s %s\n",
- ot_get_red_start (), ot_get_bold_start (),
- ot_get_bold_end (), ot_get_red_end (),
- error->message);
+ argv[0] = ext_command;
+ return ostree_command_exec_external (argv);
+ }
+ else
+ {
+ return ostree_main (argc, argv, commands);
}
-
- return ret;
}