mirror of
https://github.com/flatpak/flatpak.git
synced 2026-10-22 07:35:25 -04:00
install/update: Support -y to avoid interaction (for automation)
This assumes the answer to any question is yes (or to pick the most prioritized answer). Fixes https://github.com/flatpak/flatpak/issues/436
This commit is contained in:
1 parent
f6d1a064b9
commit
902d945f4f
4 files changed
+26
-9
No files matched your search
@@ -50,6 +50,7 @@ static gboolean opt_app;
|
||||
static gboolean opt_bundle;
|
||||
static gboolean opt_from;
|
||||
static gboolean opt_oci;
|
||||
static gboolean opt_yes;
|
||||
|
||||
static GOptionEntry options[] = {
|
||||
{ "arch", 0, 0, G_OPTION_ARG_STRING, &opt_arch, N_("Arch to install for"), N_("ARCH") },
|
||||
@@ -64,6 +65,7 @@ static GOptionEntry options[] = {
|
||||
{ "oci", 0, 0, G_OPTION_ARG_NONE, &opt_oci, N_("Assume LOCATION is an oci registry"), NULL },
|
||||
{ "gpg-file", 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &opt_gpg_file, N_("Check bundle signatures with GPG key from FILE (- for stdin)"), N_("FILE") },
|
||||
{ "subpath", 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &opt_subpaths, N_("Only install this subpath"), N_("PATH") },
|
||||
{ "assumeyes", 'y', 0, G_OPTION_ARG_NONE, &opt_yes, N_("OAutomatically answer yes for all questions"), NULL },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
@@ -226,10 +228,14 @@ handle_runtime_repo_deps (FlatpakDir *dir, GBytes *data, GError **error)
|
||||
if (old_remote != NULL)
|
||||
return TRUE;
|
||||
|
||||
if (flatpak_yes_no_prompt (_("This application depends on runtimes from:\n %s\nConfigure this as new remote '%s'"),
|
||||
if (opt_yes ||
|
||||
flatpak_yes_no_prompt (_("This application depends on runtimes from:\n %s\nConfigure this as new remote '%s'"),
|
||||
runtime_url, new_remote))
|
||||
{
|
||||
if (!flatpak_dir_modify_remote (dir, new_remote, config, gpg_key, NULL, error))
|
||||
if (opt_yes)
|
||||
g_print (_("Configuring %s as new remote '%s'"), runtime_url, new_remote);
|
||||
|
||||
if (!flatpak_dir_modify_remote (dir, new_remote, config, gpg_key, NULL, error))
|
||||
return FALSE;
|
||||
if (!flatpak_dir_recreate_repo (dir, NULL, error))
|
||||
return FALSE;
|
||||
@@ -299,7 +305,7 @@ install_from (FlatpakDir *dir,
|
||||
slash = strchr (ref, '/');
|
||||
g_print (_("Installing: %s\n"), slash + 1);
|
||||
|
||||
transaction = flatpak_transaction_new (clone, opt_no_pull, opt_no_deploy,
|
||||
transaction = flatpak_transaction_new (clone, opt_yes, opt_no_pull, opt_no_deploy,
|
||||
!opt_no_deps, !opt_no_related);
|
||||
|
||||
if (!flatpak_transaction_add_install (transaction, remote, ref, (const char **)opt_subpaths, error))
|
||||
@@ -338,7 +344,7 @@ install_oci (FlatpakDir *dir,
|
||||
registry_file = g_file_new_for_commandline_arg (registry_arg);
|
||||
registry_uri = g_file_get_uri (registry_file);
|
||||
|
||||
transaction = flatpak_transaction_new (dir, opt_no_pull, opt_no_deploy,
|
||||
transaction = flatpak_transaction_new (dir, opt_yes, opt_no_pull, opt_no_deploy,
|
||||
!opt_no_deps, !opt_no_related);
|
||||
|
||||
for (i = 0; tags[i] != NULL; i++)
|
||||
@@ -406,7 +412,7 @@ flatpak_builtin_install (int argc, char **argv, GCancellable *cancellable, GErro
|
||||
default_branch = flatpak_dir_get_remote_default_branch (dir, remote);
|
||||
kinds = flatpak_kinds_from_bools (opt_app, opt_runtime);
|
||||
|
||||
transaction = flatpak_transaction_new (dir, opt_no_pull, opt_no_deploy,
|
||||
transaction = flatpak_transaction_new (dir, opt_yes, opt_no_pull, opt_no_deploy,
|
||||
!opt_no_deps, !opt_no_related);
|
||||
|
||||
for (i = 0; i < n_prefs; i++)
|
||||
|
||||
@@ -46,6 +46,7 @@ static gboolean opt_no_deps;
|
||||
static gboolean opt_runtime;
|
||||
static gboolean opt_app;
|
||||
static gboolean opt_appstream;
|
||||
static gboolean opt_yes;
|
||||
|
||||
static GOptionEntry options[] = {
|
||||
{ "arch", 0, 0, G_OPTION_ARG_STRING, &opt_arch, N_("Arch to update for"), N_("ARCH") },
|
||||
@@ -59,6 +60,7 @@ static GOptionEntry options[] = {
|
||||
{ "app", 0, 0, G_OPTION_ARG_NONE, &opt_app, N_("Look for app with the specified name"), NULL },
|
||||
{ "appstream", 0, 0, G_OPTION_ARG_NONE, &opt_appstream, N_("Update appstream for remote"), NULL },
|
||||
{ "subpath", 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &opt_subpaths, N_("Only update this subpath"), N_("PATH") },
|
||||
{ "assumeyes", 'y', 0, G_OPTION_ARG_NONE, &opt_yes, N_("OAutomatically answer yes for all questions"), NULL },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
@@ -135,7 +137,7 @@ flatpak_builtin_update (int argc,
|
||||
n_prefs = 1;
|
||||
}
|
||||
|
||||
transaction = flatpak_transaction_new (dir, opt_no_pull, opt_no_deploy,
|
||||
transaction = flatpak_transaction_new (dir, opt_yes, opt_no_pull, opt_no_deploy,
|
||||
!opt_no_deps, !opt_no_related);
|
||||
kinds = flatpak_kinds_from_bools (opt_app, opt_runtime);
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ struct FlatpakTransaction {
|
||||
GHashTable *refs;
|
||||
GList *ops;
|
||||
|
||||
gboolean no_interaction;
|
||||
gboolean no_pull;
|
||||
gboolean no_deploy;
|
||||
gboolean add_deps;
|
||||
@@ -146,6 +147,7 @@ flatpak_transaction_operation_free (FlatpakTransactionOp *self)
|
||||
|
||||
FlatpakTransaction *
|
||||
flatpak_transaction_new (FlatpakDir *dir,
|
||||
gboolean no_interaction,
|
||||
gboolean no_pull,
|
||||
gboolean no_deploy,
|
||||
gboolean add_deps,
|
||||
@@ -156,6 +158,7 @@ flatpak_transaction_new (FlatpakDir *dir,
|
||||
t->dir = g_object_ref (dir);
|
||||
t->refs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
|
||||
|
||||
t->no_interaction = no_interaction;
|
||||
t->no_pull = no_pull;
|
||||
t->no_deploy = no_deploy;
|
||||
t->add_deps = add_deps;
|
||||
@@ -259,13 +262,18 @@ flatpak_transaction_add_op (FlatpakTransaction *self,
|
||||
}
|
||||
|
||||
static char *
|
||||
ask_for_remote (const char **remotes)
|
||||
ask_for_remote (FlatpakTransaction *self, const char **remotes)
|
||||
{
|
||||
int n_remotes = g_strv_length ((char **)remotes);
|
||||
int chosen = 0;
|
||||
int i;
|
||||
|
||||
if (n_remotes == 1)
|
||||
if (self->no_interaction)
|
||||
{
|
||||
chosen = 1;
|
||||
g_print ("Found in remote %s\n", remotes[0]);
|
||||
}
|
||||
else if (n_remotes == 1)
|
||||
{
|
||||
if (flatpak_yes_no_prompt (_("Found in remote %s, do you want to install it?"), remotes[0]))
|
||||
chosen = 1;
|
||||
@@ -364,7 +372,7 @@ add_deps (FlatpakTransaction *self,
|
||||
}
|
||||
else
|
||||
{
|
||||
runtime_remote = ask_for_remote ((const char **)remotes);
|
||||
runtime_remote = ask_for_remote (self, (const char **)remotes);
|
||||
}
|
||||
|
||||
if (runtime_remote == NULL)
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
typedef struct FlatpakTransaction FlatpakTransaction;
|
||||
|
||||
FlatpakTransaction *flatpak_transaction_new (FlatpakDir *dir,
|
||||
gboolean no_interaction,
|
||||
gboolean no_pull,
|
||||
gboolean no_deploy,
|
||||
gboolean add_deps,
|
||||
|
||||
Reference in new issue
Block a user