diff options
author | Richard Hughes <richard@hughsie.com> | 2017-05-03 12:03:48 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2017-05-03 12:03:48 +0100 |
commit | f5e42763e1c32043438b2e2b6892d9cdf7b8769b (patch) | |
tree | 78baa987c1335424e20168c4bec6fbf5ce89e06f | |
parent | 519dcb04dc0bbfbaab85ecb45dda390340a5122d (diff) | |
download | appstream-glib-f5e42763e1c32043438b2e2b6892d9cdf7b8769b.tar.gz |
trivial: Add a regex command to appstream-util for testing firmware versions
-rw-r--r-- | client/as-util.c | 29 |
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, |