summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2017-05-03 12:03:48 +0100
committerRichard Hughes <richard@hughsie.com>2017-05-03 12:03:48 +0100
commitf5e42763e1c32043438b2e2b6892d9cdf7b8769b (patch)
tree78baa987c1335424e20168c4bec6fbf5ce89e06f
parent519dcb04dc0bbfbaab85ecb45dda390340a5122d (diff)
downloadappstream-glib-f5e42763e1c32043438b2e2b6892d9cdf7b8769b.tar.gz
trivial: Add a regex command to appstream-util for testing firmware versions
-rw-r--r--client/as-util.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/client/as-util.c b/client/as-util.c
index fea9a64..5bd181f 100644
--- a/client/as-util.c
+++ b/client/as-util.c
@@ -4187,6 +4187,29 @@ as_util_sigint_cb (gpointer user_data)
return FALSE;
}
+static gboolean
+as_util_regex (AsUtilPrivate *priv, gchar **values, GError **error)
+{
+ /* check args */
+ if (g_strv_length (values) != 2) {
+ g_set_error_literal (error,
+ AS_ERROR,
+ AS_ERROR_INVALID_ARGUMENTS,
+ "expected PATTERN STRING");
+ return FALSE;
+ }
+
+ /* test */
+ if (!g_regex_match_simple (values[0], values[1], 0, 0)) {
+ g_set_error_literal (error,
+ AS_ERROR,
+ AS_ERROR_FAILED,
+ "Failed to match");
+ return FALSE;
+ }
+ return TRUE;
+}
+
int
main (int argc, char *argv[])
{
@@ -4454,6 +4477,12 @@ main (int argc, char *argv[])
/* TRANSLATORS: command description */
_("Compare version numbers"),
as_util_vercmp);
+ as_util_add (priv->cmd_array,
+ "regex",
+ NULL,
+ /* TRANSLATORS: command description */
+ _("Test a regular expression"),
+ as_util_regex);
/* sort by command name */
g_ptr_array_sort (priv->cmd_array,