extensions-tool: Add create options
As we are using git-style command syntax, we can allow for data to be provided on the command line rather than asking for it interactively. https://gitlab.gnome.org/GNOME/gnome-shell/issues/1234
This commit is contained in:
parent
0b1e29e5e3
commit
23a7aa5740
@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
#include "commands.h"
|
#include "commands.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
get_shell_version (GError **error)
|
get_shell_version (GError **error)
|
||||||
@ -172,10 +173,15 @@ prompt_metadata (char **uuid, char **name, char **description)
|
|||||||
g_autoptr (GInputStream) stdin = NULL;
|
g_autoptr (GInputStream) stdin = NULL;
|
||||||
g_autoptr (GDataInputStream) istream = NULL;
|
g_autoptr (GDataInputStream) istream = NULL;
|
||||||
|
|
||||||
|
if ((uuid == NULL || *uuid != NULL) &&
|
||||||
|
(name == NULL || *name != NULL) &&
|
||||||
|
(description == NULL || *description != NULL))
|
||||||
|
return;
|
||||||
|
|
||||||
stdin = g_unix_input_stream_new (0, FALSE);
|
stdin = g_unix_input_stream_new (0, FALSE);
|
||||||
istream = g_data_input_stream_new (stdin);
|
istream = g_data_input_stream_new (stdin);
|
||||||
|
|
||||||
if (name != NULL)
|
if (name != NULL && *name == NULL)
|
||||||
{
|
{
|
||||||
char *line;
|
char *line;
|
||||||
|
|
||||||
@ -189,7 +195,7 @@ prompt_metadata (char **uuid, char **name, char **description)
|
|||||||
*name = g_strdelimit (line, "\n", '\0');
|
*name = g_strdelimit (line, "\n", '\0');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (description != NULL)
|
if (description != NULL && *description == NULL)
|
||||||
{
|
{
|
||||||
char *line;
|
char *line;
|
||||||
|
|
||||||
@ -203,7 +209,7 @@ prompt_metadata (char **uuid, char **name, char **description)
|
|||||||
*description = g_strdelimit (line, "\n", '\0');
|
*description = g_strdelimit (line, "\n", '\0');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uuid != NULL)
|
if (uuid != NULL && *uuid == NULL)
|
||||||
{
|
{
|
||||||
char *line;
|
char *line;
|
||||||
|
|
||||||
@ -225,12 +231,32 @@ handle_create (int argc, char *argv[], gboolean do_help)
|
|||||||
g_autofree char *name = NULL;
|
g_autofree char *name = NULL;
|
||||||
g_autofree char *description = NULL;
|
g_autofree char *description = NULL;
|
||||||
g_autofree char *uuid = NULL;
|
g_autofree char *uuid = NULL;
|
||||||
|
gboolean interactive = FALSE;
|
||||||
|
GOptionEntry entries[] = {
|
||||||
|
{ .long_name = "uuid",
|
||||||
|
.arg = G_OPTION_ARG_STRING, .arg_data = &uuid,
|
||||||
|
.arg_description = "UUID",
|
||||||
|
.description = _("The unique identifier of the new extension") },
|
||||||
|
{ .long_name = "name",
|
||||||
|
.arg = G_OPTION_ARG_STRING, .arg_data = &name,
|
||||||
|
.arg_description = _("NAME"),
|
||||||
|
.description = _("The user-visible name of the new extension") },
|
||||||
|
{ .long_name = "description",
|
||||||
|
.arg_description = _("DESCRIPTION"),
|
||||||
|
.arg = G_OPTION_ARG_STRING, .arg_data = &description,
|
||||||
|
.description = _("A short description of what the extension does") },
|
||||||
|
{ .long_name = "interactive", .short_name = 'i',
|
||||||
|
.arg = G_OPTION_ARG_NONE, .arg_data = &interactive,
|
||||||
|
.description = _("Enter extension information interactively") },
|
||||||
|
{ NULL }
|
||||||
|
};
|
||||||
|
|
||||||
g_set_prgname ("gnome-extensions create");
|
g_set_prgname ("gnome-extensions create");
|
||||||
|
|
||||||
context = g_option_context_new (NULL);
|
context = g_option_context_new (NULL);
|
||||||
g_option_context_set_help_enabled (context, FALSE);
|
g_option_context_set_help_enabled (context, FALSE);
|
||||||
g_option_context_set_summary (context, _("Create a new extension"));
|
g_option_context_set_summary (context, _("Create a new extension"));
|
||||||
|
g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
|
||||||
|
|
||||||
if (do_help)
|
if (do_help)
|
||||||
{
|
{
|
||||||
@ -250,7 +276,14 @@ handle_create (int argc, char *argv[], gboolean do_help)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
prompt_metadata (&uuid, &name, &description);
|
if (interactive)
|
||||||
|
prompt_metadata (&uuid, &name, &description);
|
||||||
|
|
||||||
|
if (uuid == NULL || name == NULL || description == NULL)
|
||||||
|
{
|
||||||
|
show_help (context, _("UUID, name and description are required"));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
return create_extension (uuid, name, description) ? 0 : 2;
|
return create_extension (uuid, name, description) ? 0 : 2;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user