diff --git a/Makefile.am b/Makefile.am index 1d3882bf..153eee4e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -16,6 +16,7 @@ xdg_app_SOURCES = \ xdg-app-main.c \ xdg-app-builtins.h \ xdg-app-builtins-add-repo.c \ + xdg-app-builtins-delete-repo.c \ xdg-app-builtins-install.c \ xdg-app-builtins-update.c \ xdg-app-builtins-run.c \ diff --git a/xdg-app-builtins-delete-repo.c b/xdg-app-builtins-delete-repo.c new file mode 100644 index 00000000..5b7c8e61 --- /dev/null +++ b/xdg-app-builtins-delete-repo.c @@ -0,0 +1,53 @@ +#include "config.h" + +#include +#include +#include + +#include "libgsystem.h" + +#include "xdg-app-builtins.h" + +static void +usage_error (GOptionContext *context, const char *message, GError **error) +{ + gs_free gchar *help = g_option_context_get_help (context, TRUE, NULL); + g_printerr ("%s", help); + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, message); +} + +gboolean +xdg_app_builtin_delete_repo (int argc, char **argv, GCancellable *cancellable, GError **error) +{ + GOptionContext *context; + gboolean ret = FALSE; + gs_unref_object XdgAppDir *dir = NULL; + const char *remote_name; + + context = g_option_context_new ("NAME - Delete a remote repository"); + + if (!xdg_app_option_context_parse (context, NULL, &argc, &argv, 0, &dir, cancellable, error)) + goto out; + + if (argc < 2) + { + usage_error (context, "NAME must be specified", error); + goto out; + } + + remote_name = argv[1]; + + if (!ostree_repo_remote_change (xdg_app_dir_get_repo (dir), NULL, + OSTREE_REPO_REMOTE_CHANGE_DELETE, + remote_name, NULL, + NULL, + cancellable, error)) + goto out; + + ret = TRUE; + + out: + if (context) + g_option_context_free (context); + return ret; +} diff --git a/xdg-app-builtins.h b/xdg-app-builtins.h index ebcaa40b..1045a4a8 100644 --- a/xdg-app-builtins.h +++ b/xdg-app-builtins.h @@ -25,6 +25,7 @@ gboolean xdg_app_option_context_parse (GOptionContext *context, #define BUILTINPROTO(name) gboolean xdg_app_builtin_ ## name (int argc, char **argv, GCancellable *cancellable, GError **error) BUILTINPROTO(add_repo); +BUILTINPROTO(delete_repo); BUILTINPROTO(install_runtime); BUILTINPROTO(update_runtime); BUILTINPROTO(install_app); diff --git a/xdg-app-main.c b/xdg-app-main.c index 167659e6..c5fd6fbe 100644 --- a/xdg-app-main.c +++ b/xdg-app-main.c @@ -20,6 +20,7 @@ typedef struct { static XdgAppCommand commands[] = { { "add-repo", xdg_app_builtin_add_repo }, + { "delete-repo", xdg_app_builtin_delete_repo }, { "install-runtime", xdg_app_builtin_install_runtime }, { "update-runtime", xdg_app_builtin_update_runtime }, { "install-app", xdg_app_builtin_install_app },