extensions-tool: Add --template create option

We now have everything in place to allow users to pick a template
other than the default one (although at the moment it's the only
one we have), so add a corresponding option.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/812
This commit is contained in:
Florian Müllner 2019-11-07 12:46:47 +01:00 committed by Florian Müllner
parent fd034e3551
commit 6f6251c0bc
3 changed files with 22 additions and 3 deletions

View File

@ -44,6 +44,14 @@ __gnome_extensions() {
esac
case "$COMMAND" in
create)
case "$prev" in
--template)
COMPREPLY=($(compgen -W "`gnome-extensions create --list-templates`" -- "$2"))
return 0
;;
esac
;;
pack)
case "$prev" in
--podir|--out-dir|-o)

View File

@ -128,6 +128,9 @@ Creates a new extension from a template.
*--uuid*='UUID':::
Set the unique extension ID in the metadata to 'UUID'
*--template*='TEMPLATE':::
Use 'TEMPLATE' as base for the new extension
*-i*:::
*--interactive*:::
Prompt for any extension metadata that hasn't been provided

View File

@ -208,11 +208,14 @@ launch_extension_source (GFile *dir, GError **error)
}
static gboolean
create_extension (const char *uuid, const char *name, const char *description)
create_extension (const char *uuid, const char *name, const char *description, const char *template)
{
g_autoptr (GFile) dir = NULL;
g_autoptr (GError) error = NULL;
if (template == NULL)
template = "plain";
dir = g_file_new_build_filename (g_get_user_data_dir (),
"gnome-shell",
"extensions",
@ -231,7 +234,7 @@ create_extension (const char *uuid, const char *name, const char *description)
return FALSE;
}
if (!copy_extension_template ("plain", dir, &error))
if (!copy_extension_template (template, dir, &error))
{
g_printerr ("%s\n", error->message);
return FALSE;
@ -328,6 +331,7 @@ handle_create (int argc, char *argv[], gboolean do_help)
g_autofree char *name = NULL;
g_autofree char *description = NULL;
g_autofree char *uuid = NULL;
g_autofree char *template = NULL;
gboolean interactive = FALSE;
gboolean list_templates = FALSE;
GOptionEntry entries[] = {
@ -343,6 +347,10 @@ handle_create (int argc, char *argv[], gboolean do_help)
.arg_description = _("DESCRIPTION"),
.arg = G_OPTION_ARG_STRING, .arg_data = &description,
.description = _("A short description of what the extension does") },
{ .long_name = "template",
.arg = G_OPTION_ARG_STRING, .arg_data = &template,
.arg_description = _("TEMPLATE"),
.description = _("The template to use for the new extension") },
{ .long_name = "list-templates",
.arg = G_OPTION_ARG_NONE, .arg_data = &list_templates,
.flags = G_OPTION_FLAG_HIDDEN },
@ -403,5 +411,5 @@ handle_create (int argc, char *argv[], gboolean do_help)
return 1;
}
return create_extension (uuid, name, description) ? 0 : 2;
return create_extension (uuid, name, description, template) ? 0 : 2;
}