From f117985e376b6ebf9f4f63e653bc4593dd53747c Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Wed, 19 Oct 2016 18:00:12 +0200 Subject: [PATCH] remote-add: Make --from a boolean arg instead of a string arg So before you did: flatpak --user remote-add --from=https://sdk.gnome.org/gnome.flatpakrepo gnome Now you do: flatpak --user remote-add --from gnome https://sdk.gnome.org/gnome.flatpakrepo This is a somewhat break, but this means we handle --from the same in remote-add and install, which seems important. --- app/flatpak-builtins-add-remote.c | 27 +++++++++++++++------------ doc/flatpak-remote-add.xml | 8 +------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/app/flatpak-builtins-add-remote.c b/app/flatpak-builtins-add-remote.c index bee9fefe5..247c1b07a 100644 --- a/app/flatpak-builtins-add-remote.c +++ b/app/flatpak-builtins-add-remote.c @@ -57,13 +57,13 @@ static int opt_prio = -1; static char *opt_title; static char *opt_default_branch; static char *opt_url; -static char *opt_from; +static gboolean opt_from; static char **opt_gpg_import; static GOptionEntry add_options[] = { { "if-not-exists", 0, 0, G_OPTION_ARG_NONE, &opt_if_not_exists, N_("Do nothing if the provided remote exists"), NULL }, - { "from", 0, 0, G_OPTION_ARG_FILENAME, &opt_from, N_("Load options from file or uri"), N_("FILE/URI") }, + { "from", 0, 0, G_OPTION_ARG_NONE, &opt_from, N_("Load options from file or uri"), NULL }, { NULL } }; @@ -219,7 +219,7 @@ get_config_from_opts (FlatpakDir *dir, const char *remote_name) } static void -load_options (char *filename, +load_options (const char *filename, GBytes **gpg_data) { g_autoptr(GError) error = NULL; @@ -354,7 +354,7 @@ flatpak_builtin_add_remote (int argc, char **argv, g_auto(GStrv) remotes = NULL; g_autofree char *remote_url = NULL; const char *remote_name; - const char *url_or_path = NULL; + const char *location = NULL; g_autoptr(GKeyFile) config = NULL; g_autoptr(GBytes) gpg_data = NULL; @@ -366,19 +366,17 @@ flatpak_builtin_add_remote (int argc, char **argv, if (!flatpak_option_context_parse (context, add_options, &argc, &argv, 0, &dir, cancellable, error)) return FALSE; - if (opt_from) - load_options (opt_from, &gpg_data); - if (argc < 2) return usage_error (context, _("NAME must be specified"), error); - if (argc < 3 && opt_url == NULL) + if (argc < 3) return usage_error (context, _("LOCATION must be specified"), error); if (argc > 3) return usage_error (context, _("Too many arguments"), error); remote_name = argv[1]; + location = argv[2]; remotes = flatpak_dir_list_remotes (dir, cancellable, error); if (remotes == NULL) @@ -392,14 +390,19 @@ flatpak_builtin_add_remote (int argc, char **argv, return flatpak_fail (error, _("Remote %s already exists"), remote_name); } - if (opt_url == NULL) + if (opt_from) { - url_or_path = argv[2]; - file = g_file_new_for_commandline_arg (url_or_path); + load_options (location, &gpg_data); + if (opt_url == NULL) + return flatpak_fail (error, _("No url specified in flatpakrepo file")); + } + else + { + file = g_file_new_for_commandline_arg (location); if (g_file_is_native (file)) remote_url = g_file_get_uri (file); else - remote_url = g_strdup (url_or_path); + remote_url = g_strdup (location); opt_url = remote_url; } diff --git a/doc/flatpak-remote-add.xml b/doc/flatpak-remote-add.xml index 926405203..c863ca6b9 100644 --- a/doc/flatpak-remote-add.xml +++ b/doc/flatpak-remote-add.xml @@ -35,12 +35,6 @@ NAME LOCATION - - flatpak remote-add - OPTION - --from - FILENAME or URL - @@ -81,7 +75,7 @@ - Add from a flatpakrepo file (local or http uri) instead of from commandline arguments. + Add from a flatpakrepo file (local or http uri) instead of from commandline arguments. This means the LOCATION argument specifies the filename/uri of a flatpakref rather than a repo url.