From 513b3c09a54af31ffd1b0eb9b3c47849816483be Mon Sep 17 00:00:00 2001 From: Luca BRUNO Date: Mon, 20 Dec 2021 10:00:02 +0000 Subject: 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`. --- src/ostree/main.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) (limited to 'src/ostree/main.c') 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 #include #include -#include #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; } -- cgit v1.2.1