diff options
author | Richard Hughes <richard@hughsie.com> | 2014-04-21 12:54:26 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2014-04-21 12:54:26 +0100 |
commit | b63f0080aaa83ef35251f42544de3fe3b96f0531 (patch) | |
tree | 2ecf56a8f463b46e03abb56be2f84abfb8eb7ed7 /client | |
parent | 6a8d7f2b3a817c0b69cf58432a1985bd9df8a221 (diff) | |
download | appstream-glib-b63f0080aaa83ef35251f42544de3fe3b96f0531.tar.gz |
Add a 'validate' command to appstream-util
Diffstat (limited to 'client')
-rw-r--r-- | client/as-util.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/client/as-util.c b/client/as-util.c index 7bc16fe..64342cc 100644 --- a/client/as-util.c +++ b/client/as-util.c @@ -1000,6 +1000,64 @@ out: } /** + * as_util_validate: + **/ +static gboolean +as_util_validate (AsUtilPrivate *priv, gchar **values, GError **error) +{ + AsApp *app = NULL; + AsProblemKind kind; + AsProblem *problem; + GPtrArray *probs = NULL; + gboolean ret = TRUE; + guint i; + + /* check args */ + if (g_strv_length (values) != 1) { + ret = FALSE; + g_set_error_literal (error, + AS_ERROR, + AS_ERROR_INVALID_ARGUMENTS, + "Not enough arguments, " + "expected example.appdata.xml"); + goto out; + } + + /* load file */ + app = as_app_new (); + as_app_parse_file (app, values[0], AS_APP_PARSE_FLAG_NONE, error); + if (!ret) + goto out; + probs = as_app_validate (app, AS_APP_VALIDATE_FLAG_NONE, error); + if (probs == NULL) { + ret = FALSE; + goto out; + } + if (probs->len == 0) { + g_print ("%s\n", _("File validated successfully!")); + } else { + ret = FALSE; + g_set_error_literal (error, + AS_ERROR, + AS_ERROR_INVALID_ARGUMENTS, + _("Validation failed")); + } + for (i = 0; i < probs->len; i++) { + problem = g_ptr_array_index (probs, i); + kind = as_problem_get_kind (problem); + g_print ("%s\t%s\n", + as_problem_kind_to_string (kind), + as_problem_get_message (problem)); + } +out: + if (probs != NULL) + g_ptr_array_unref (probs); + if (app != NULL) + g_object_unref (app); + return ret; +} + +/** * as_util_ignore_cb: **/ static void @@ -1074,6 +1132,12 @@ main (int argc, char *argv[]) /* TRANSLATORS: command description */ _("List applications not backed by packages"), as_util_non_package_yaml); + as_util_add (priv->cmd_array, + "validate", + NULL, + /* TRANSLATORS: command description */ + _("Validate an AppData or AppStream file"), + as_util_validate); /* sort by command name */ g_ptr_array_sort (priv->cmd_array, |