Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ascli: Allow searching by categories #447

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -416,6 +416,36 @@ as_client_run_what_provides (const gchar *command, char **argv, int argc)
optn_details);
}

/**
* as_client_run_by_categories:
*
* Lists components by their categories.
*/

static int
as_client_run_by_categories (const gchar *command, char **argv, int argc)
{

g_autoptr(GOptionContext) opt_context = NULL;
gint ret;
const gchar *value = NULL;

opt_context = as_client_new_subcommand_option_context (command, find_options);
g_option_context_add_main_entries (opt_context, data_collection_options, NULL);

ret = as_client_option_context_parse (opt_context, command, &argc, &argv);
if (ret != 0)
return ret;

if (argc > 2)
value = argv[2];

return ascli_by_categories (optn_cachepath,
value,
optn_details,
optn_no_cache);
}

/**
* as_client_run_validate:
*
@@ -1252,6 +1282,12 @@ as_client_run (char **argv, int argc)
/* TRANSLATORS: `appstreamcli what-provides` command description. */
_("Get components which provide the given item. Needs an item type (e.g. lib, bin, python3, …) and item value as parameter."),
as_client_run_what_provides);
ascli_add_cmd (commands,
0, "by-categories", NULL, "NAMES",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about the naming here... It would make sense to implement this as a search filter, to search by category in appstreamcli search, but if this stays the way it is something like category-contents might make more sense: appstreamcli category-contents AudioVideo or appstreamcli search --by-category=AudioVideo mysearchterm.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I don't mind either way. In fairness, I'd forgotten about this PR already.

/* TRANSLATORS: `appstreamcli what-provides` command description. */
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Translator hint needs update.

_("Get components that are part of the specified categories in a list with comas (,)."),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Maybe better: List components that are part of the specified categories (listed separated by commas).

as_client_run_by_categories);


ascli_add_cmd (commands,
1, "dump", NULL, "COMPONENT-ID",
@@ -252,6 +252,50 @@ ascli_what_provides (const gchar *cachepath, const gchar *kind_str, const gchar
return 0;
}

/**
* ascli_by_categories:
*
* Get components that match the given @p categories
*/
int
ascli_by_categories (const gchar *cachepath, const gchar *categories, gboolean detailed, gboolean no_cache)
{
g_autoptr(AsPool) dpool = NULL;
g_autoptr(GPtrArray) result = NULL;
g_autoptr(GError) error = NULL;

if (categories == NULL) {
fprintf (stderr, "%s\n", _("You need to specify a categories to look up."));
return 2;
}

dpool = ascli_data_pool_new_and_open (cachepath, no_cache, &error);
if (error != NULL) {
g_printerr ("%s\n", error->message);
return 1;
}

g_auto(GStrv) cats = g_strsplit(categories, ",", 0);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No declarations after statements please, we (still) need to be compatible with older C versions/compilers.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I've ever seen a compiler that required it and I've been doing C for about 20 years now.


result = as_pool_get_components_by_categories (dpool, cats);
if (result->len == 0) {
/* TRANSLATORS: We failed to find any component in the database, likely due to an error */
ascli_print_stderr (_("Unable to find components matching %s!"), categories);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Maybe just call it Unable to find components in categories "%s"! to make this more clear?

return 4;
}

if (result->len == 0) {
/* TRANSLATORS: We got no full-text search results */
ascli_print_stdout (_("No component matching '%s' categories found."), categories);
return 0;
}

/* show the result */
ascli_print_components (result, detailed);

return 0;
}

/**
* ascli_dump_component:
*
@@ -66,6 +66,10 @@ int ascli_create_metainfo_template (const gchar *out_fname,
const gchar *cpt_kind_str,
const gchar *desktop_file);

int ascli_by_categories (const gchar *cachepath,
const gchar *categories,
gboolean detailed,
gboolean no_cache);

G_END_DECLS