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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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", | ||
| /* TRANSLATORS: `appstreamcli what-provides` command description. */ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 (,)."), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Maybe better: |
||
| as_client_run_by_categories); | ||
|
|
||
|
|
||
| ascli_add_cmd (commands, | ||
| 1, "dump", NULL, "COMPONENT-ID", | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Maybe just call it |
||
| 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: | ||
| * | ||
There was a problem hiding this comment.
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 likecategory-contentsmight make more sense:appstreamcli category-contents AudioVideoorappstreamcli search --by-category=AudioVideo mysearchterm.There was a problem hiding this comment.
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.