summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2016-09-06 09:13:30 +0100
committerRichard Hughes <richard@hughsie.com>2016-09-06 09:13:30 +0100
commit2b83a4c95cae09811919518c60695a8d9bfe31dc (patch)
tree1788107ce39a0f4419db148e78aad0bf12e815d2 /client
parent535c4ed89fcff27288969777500a26fe19941b94 (diff)
downloadappstream-glib-2b83a4c95cae09811919518c60695a8d9bfe31dc.tar.gz
Add an easy way to add a language to an existing file
Diffstat (limited to 'client')
-rw-r--r--client/as-util.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/client/as-util.c b/client/as-util.c
index b5a9970..dd30bae 100644
--- a/client/as-util.c
+++ b/client/as-util.c
@@ -3508,6 +3508,48 @@ as_util_add_provide (AsUtilPrivate *priv, gchar **values, GError **error)
return TRUE;
}
+static gboolean
+as_util_add_language (AsUtilPrivate *priv, gchar **values, GError **error)
+{
+ GPtrArray *screenshots;
+ guint i;
+ gint percentage = 0;
+ g_autoptr(AsApp) app = NULL;
+ g_autoptr(GFile) file = NULL;
+
+ /* check args */
+ if (g_strv_length (values) < 2) {
+ g_set_error_literal (error,
+ AS_ERROR,
+ AS_ERROR_INVALID_ARGUMENTS,
+ "Not enough arguments, expected: file locale [value]");
+ return FALSE;
+ }
+
+ /* parse file */
+ app = as_app_new ();
+ if (!as_app_parse_file (app, values[0],
+ AS_APP_PARSE_FLAG_KEEP_COMMENTS, error))
+ return FALSE;
+
+ /* parse optional percentage and add locale */
+ if (g_strv_length (values) > 2) {
+ guint64 tmp = g_ascii_strtoull (values[2], NULL, 10);
+ if (tmp == 0 || tmp > 100) {
+ g_set_error (error,
+ AS_ERROR,
+ AS_ERROR_INVALID_ARGUMENTS,
+ "failed to parse percentage: %s",
+ values[2]);
+ return FALSE;
+ }
+ percentage = (gint) tmp;
+ }
+ as_app_add_language (app, percentage, values[1]);
+ file = g_file_new_for_path (values[0]);
+ return as_app_to_file (app, file, NULL, error);
+}
+
static void
as_util_pad_strings (const gchar *id, const gchar *msg, guint align)
{
@@ -4193,6 +4235,12 @@ main (int argc, char *argv[])
_("Add a provide to a source file"),
as_util_add_provide);
as_util_add (priv->cmd_array,
+ "add-language",
+ NULL,
+ /* TRANSLATORS: command description */
+ _("Add a language to a source file"),
+ as_util_add_language);
+ as_util_add (priv->cmd_array,
"mirror-screenshots",
NULL,
/* TRANSLATORS: command description */