Allow specifying partial refs as name in commands

The commands: install, update, uninstall, info, make-current and run
now supports specifying a partial ref for the name. This is a different
way of specifying optional arch and branch arguments.

For instance org.app.App//master is the same as "org.app.App master" or
"--branch=master org.app.App".

This is useful if you're cutting and pasting from e.g. the list -d output.
tingping/wmclass
Alexander Larsson 2016-08-24 09:18:00 +02:00
parent 23c1c22266
commit 54c5f9a59e
8 changed files with 94 additions and 19 deletions

View File

@ -63,8 +63,8 @@ flatpak_builtin_info (int argc, char **argv, GCancellable *cancellable, GError *
FlatpakDir *dir = NULL;
g_autoptr(GError) lookup_error = NULL;
g_autoptr(GVariant) deploy_data = NULL;
const char *name;
const char *branch = NULL;
char *name;
char *branch = NULL;
const char *commit = NULL;
const char *origin = NULL;
gboolean is_app = FALSE;
@ -83,6 +83,9 @@ flatpak_builtin_info (int argc, char **argv, GCancellable *cancellable, GError *
if (argc >= 3)
branch = argv[2];
if (!flatpak_split_partial_ref_arg (name, &opt_arch, &branch, error))
return FALSE;
if (!opt_app && !opt_runtime)
opt_app = opt_runtime = TRUE;

View File

@ -141,8 +141,8 @@ flatpak_builtin_install (int argc, char **argv, GCancellable *cancellable, GErro
g_autoptr(GOptionContext) context = NULL;
g_autoptr(FlatpakDir) dir = NULL;
const char *repository;
const char *name;
const char *branch = NULL;
char *name;
char *branch = NULL;
g_autofree char *ref = NULL;
gboolean is_app;
g_autoptr(GFile) deploy_dir = NULL;
@ -166,6 +166,9 @@ flatpak_builtin_install (int argc, char **argv, GCancellable *cancellable, GErro
if (argc >= 4)
branch = argv[3];
if (!flatpak_split_partial_ref_arg (name, &opt_arch, &branch, error))
return FALSE;
if (!opt_app && !opt_runtime)
opt_app = opt_runtime = TRUE;

View File

@ -45,8 +45,8 @@ flatpak_builtin_make_current_app (int argc, char **argv, GCancellable *cancellab
g_autoptr(GOptionContext) context = NULL;
g_autoptr(FlatpakDir) dir = NULL;
g_autoptr(GFile) deploy_base = NULL;
const char *app;
const char *branch = "master";
char *app;
char *branch = NULL;
g_autofree char *ref = NULL;
g_auto(GLnxLockFile) lock = GLNX_LOCK_FILE_INIT;
@ -56,11 +56,19 @@ flatpak_builtin_make_current_app (int argc, char **argv, GCancellable *cancellab
if (!flatpak_option_context_parse (context, options, &argc, &argv, 0, &dir, cancellable, error))
return FALSE;
if (argc < 3)
return usage_error (context, _("APP and BRANCH must be specified"), error);
if (argc < 2)
return usage_error (context, _("APP must be specified"), error);
app = argv[1];
branch = argv[2];
if (argc >= 3)
branch = argv[2];
if (!flatpak_split_partial_ref_arg (app, &opt_arch, &branch, error))
return FALSE;
if (branch == NULL)
return usage_error (context, _("BRANCH must be specified"), error);
ref = flatpak_dir_find_installed_ref (dir,
app,

View File

@ -63,8 +63,7 @@ flatpak_builtin_run (int argc, char **argv, GCancellable *cancellable, GError **
g_autoptr(GOptionContext) context = NULL;
g_autoptr(FlatpakDeploy) app_deploy = NULL;
g_autofree char *app_ref = NULL;
const char *app;
const char *branch = "master";
char *app;
int i;
int rest_argv_start, rest_argc;
g_autoptr(FlatpakContext) arg_context = NULL;
@ -96,8 +95,8 @@ flatpak_builtin_run (int argc, char **argv, GCancellable *cancellable, GError **
app = argv[rest_argv_start];
if (opt_branch)
branch = opt_branch;
if (!flatpak_split_partial_ref_arg (app, &opt_arch, &opt_branch, error))
return FALSE;
if (opt_branch == NULL && opt_arch == NULL)
{
@ -111,7 +110,7 @@ flatpak_builtin_run (int argc, char **argv, GCancellable *cancellable, GError **
if (app_ref == NULL)
{
app_ref = flatpak_compose_ref (TRUE, app, branch, opt_arch, error);
app_ref = flatpak_compose_ref (TRUE, app, opt_branch, opt_arch, error);
if (app_ref == NULL)
return FALSE;
}

View File

@ -54,8 +54,8 @@ flatpak_builtin_uninstall (int argc, char **argv, GCancellable *cancellable, GEr
{
g_autoptr(GOptionContext) context = NULL;
g_autoptr(FlatpakDir) dir = NULL;
const char *name = NULL;
const char *branch = NULL;
char *name = NULL;
char *branch = NULL;
g_autofree char *ref = NULL;
gboolean is_app;
FlatpakHelperUninstallFlags flags = 0;
@ -69,12 +69,15 @@ flatpak_builtin_uninstall (int argc, char **argv, GCancellable *cancellable, GEr
return FALSE;
if (argc < 2)
return usage_error (context, _("APP must be specified"), error);
return usage_error (context, _("NAME must be specified"), error);
name = argv[1];
if (argc > 2)
branch = argv[2];
if (!flatpak_split_partial_ref_arg (name, &opt_arch, &branch, error))
return FALSE;
if (!opt_app && !opt_runtime)
opt_app = opt_runtime = TRUE;

View File

@ -198,8 +198,8 @@ flatpak_builtin_update (int argc,
{
g_autoptr(GOptionContext) context = NULL;
g_autoptr(FlatpakDir) dir = NULL;
const char *name = NULL;
const char *branch = NULL;
char *name = NULL;
char *branch = NULL;
gboolean failed = FALSE;
gboolean found = FALSE;
int i;
@ -218,6 +218,9 @@ flatpak_builtin_update (int argc,
if (opt_arch == NULL)
opt_arch = (char *)flatpak_get_arch ();
if (!flatpak_split_partial_ref_arg (name, &opt_arch, &branch, error))
return FALSE;
if (!opt_app && !opt_runtime)
opt_app = opt_runtime = TRUE;

View File

@ -562,6 +562,57 @@ flatpak_decompose_ref (const char *full_ref,
return g_steal_pointer (&parts);
}
gboolean
flatpak_split_partial_ref_arg (char *partial_ref,
char **inout_arch,
char **inout_branch,
GError **error)
{
char *slash;
char *arch = NULL;
char *branch = NULL;
slash = strchr (partial_ref, '/');
if (slash != NULL)
*slash = 0;
if (!flatpak_is_valid_name (partial_ref))
return flatpak_fail (error, "Invalid name %s", partial_ref);
if (slash == NULL)
goto out;
arch = slash + 1;
slash = strchr (arch, '/');
if (slash != NULL)
*slash = 0;
if (strlen (arch) == 0)
arch = NULL;
if (slash == NULL)
goto out;
branch = slash + 1;
if (strlen (branch) > 0)
{
if (!flatpak_is_valid_branch (branch))
return flatpak_fail (error, "Invalid branch %s", branch);
}
else
branch = NULL;
out:
if (*inout_arch == NULL)
*inout_arch = arch;
if (*inout_branch == NULL)
*inout_branch = branch;
return TRUE;
}
char *
flatpak_compose_ref (gboolean app,
const char *name,

View File

@ -74,6 +74,11 @@ gboolean flatpak_is_valid_branch (const char *string);
char **flatpak_decompose_ref (const char *ref,
GError **error);
gboolean flatpak_split_partial_ref_arg (char *partial_ref,
char **inout_arch,
char **inout_branch,
GError **error);
char * flatpak_compose_ref (gboolean app,
const char *name,
const char *branch,