update: better logging and search improvements

This commit is contained in:
ngn 2024-08-22 03:33:52 +03:00
parent 86b1481774
commit 4f4db1963d
11 changed files with 154 additions and 91 deletions

View File

@ -11,7 +11,7 @@ OBJS = $(patsubst src/%.c,dist/%.o,$(SRCS))
CFLAGS = -O3 -fstack-protector-strong -fcf-protection=full -fstack-clash-protection CFLAGS = -O3 -fstack-protector-strong -fcf-protection=full -fstack-clash-protection
LIBS = -linih -lmp LIBS = -linih -lmp
VERSION = 24.01 VERSION = 24.02
all: dist dist/matt $(PO_OUTS) all: dist dist/matt $(PO_OUTS)

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-08-22 02:15+0300\n" "POT-Creation-Date: 2024-08-22 03:32+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -17,11 +17,11 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
#: src/callback.c:34 src/callback.c:49 #: src/callback.c:36 src/callback.c:53
msgid "Failed to sync " msgid "Failed to sync "
msgstr "Failed to sync " msgstr "Failed to sync "
#: src/callback.c:43 src/cmd/sync.c:32 #: src/callback.c:47 src/cmd/sync.c:46
msgid "Synced " msgid "Synced "
msgstr "Synced " msgstr "Synced "
@ -155,7 +155,9 @@ msgstr "Displaying help information"
msgid "MatterLinux package manager %s (libmp %s)" msgid "MatterLinux package manager %s (libmp %s)"
msgstr "MatterLinux package manager %s (libmp %s)" msgstr "MatterLinux package manager %s (libmp %s)"
#: src/main.c:188 #: src/main.c:188 src/cmd/info.c:47 src/cmd/install.c:33 src/cmd/list.c:23
#: src/cmd/remove.c:27 src/cmd/search.c:197 src/cmd/sync.c:23
#: src/cmd/update.c:22
msgid "Usage: " msgid "Usage: "
msgstr "Usage: " msgstr "Usage: "
@ -171,17 +173,18 @@ msgstr "To list different options, use commands with "
msgid "Here is a list of available global options:" msgid "Here is a list of available global options:"
msgstr "Here is a list of available global options:" msgstr "Here is a list of available global options:"
#: src/main.c:200 src/main.c:201 src/cmd/info.c:48 src/cmd/info.c:49 #: src/main.c:200 src/main.c:201 src/main.c:202 src/cmd/info.c:49
#: src/cmd/info.c:50 src/cmd/install.c:34 src/cmd/install.c:35 #: src/cmd/info.c:50 src/cmd/info.c:51 src/cmd/install.c:35
#: src/cmd/install.c:36 src/cmd/install.c:37 src/cmd/install.c:38 #: src/cmd/install.c:36 src/cmd/install.c:37 src/cmd/install.c:38
#: src/cmd/list.c:24 src/cmd/list.c:25 src/cmd/remove.c:28 src/cmd/remove.c:29 #: src/cmd/install.c:39 src/cmd/list.c:25 src/cmd/list.c:26 src/cmd/remove.c:29
#: src/cmd/search.c:170 src/cmd/search.c:171 src/cmd/search.c:172 #: src/cmd/remove.c:30 src/cmd/search.c:199 src/cmd/search.c:200
#: src/cmd/search.c:173 src/cmd/update.c:23 #: src/cmd/search.c:201 src/cmd/search.c:202 src/cmd/sync.c:25
#: src/cmd/update.c:24
#, c-format #, c-format
msgid " " msgid " "
msgstr " " msgstr " "
#: src/main.c:203 #: src/main.c:204
msgid "" msgid ""
"Licensed under GPLv3, see https://www.gnu.org/licenses/ for more information" "Licensed under GPLv3, see https://www.gnu.org/licenses/ for more information"
msgstr "" msgstr ""
@ -201,235 +204,240 @@ msgstr "Failed to run the editor: %s"
msgid "Failed to open the editor: %s" msgid "Failed to open the editor: %s"
msgstr "Failed to open the editor: %s" msgstr "Failed to open the editor: %s"
#: src/cmd/info.c:13 src/cmd/info.c:23 src/cmd/install.c:91 src/cmd/remove.c:52 #: src/cmd/info.c:13 src/cmd/info.c:23 src/cmd/install.c:92 src/cmd/remove.c:53
msgid "Package " msgid "Package "
msgstr "Package " msgstr "Package "
#: src/cmd/info.c:42 src/cmd/install.c:28 src/cmd/list.c:18 src/cmd/remove.c:22 #: src/cmd/info.c:42 src/cmd/install.c:28 src/cmd/list.c:18 src/cmd/remove.c:22
#: src/cmd/search.c:164 src/cmd/sync.c:15 src/cmd/update.c:17 #: src/cmd/search.c:192 src/cmd/sync.c:18 src/cmd/update.c:17
msgid "Unknown argument: " msgid "Unknown argument: "
msgstr "Unknown argument: " msgstr "Unknown argument: "
#: src/cmd/info.c:47 src/cmd/list.c:23 src/cmd/search.c:169 #: src/cmd/info.c:48 src/cmd/list.c:24 src/cmd/search.c:198 src/cmd/sync.c:24
msgid "Listing options for the list command:" msgid "Listing options for the list command:"
msgstr "Listing options for the list command:" msgstr "Listing options for the list command:"
#: src/cmd/info.c:71 #: src/cmd/info.c:72
msgid "Please specify only a single package name" msgid "Please specify only a single package name"
msgstr "Please specify only a single package name" msgstr "Please specify only a single package name"
#: src/cmd/info.c:78 #: src/cmd/info.c:79
msgid "Please specify a single package" msgid "Please specify a single package"
msgstr "Please specify a single package" msgstr "Please specify a single package"
#: src/cmd/info.c:93 #: src/cmd/info.c:94
msgid "Failed to get the changes file for " msgid "Failed to get the changes file for "
msgstr "Failed to get the changes file for " msgstr "Failed to get the changes file for "
#: src/cmd/info.c:99 #: src/cmd/info.c:100
msgid "Failed to access the changes file, is the package installed?" msgid "Failed to access the changes file, is the package installed?"
msgstr "Failed to access the changes file, is the package installed?" msgstr "Failed to access the changes file, is the package installed?"
#: src/cmd/info.c:106 #: src/cmd/info.c:107
msgid "Failed to get the depends list for " msgid "Failed to get the depends list for "
msgstr "Failed to get the depends list for " msgstr "Failed to get the depends list for "
#: src/cmd/info.c:134 #: src/cmd/info.c:135
#, c-format #, c-format
msgid "Name " msgid "Name "
msgstr "Name " msgstr "Name "
#: src/cmd/info.c:135 #: src/cmd/info.c:136
#, c-format #, c-format
msgid "Version " msgid "Version "
msgstr "Version " msgstr "Version "
#: src/cmd/info.c:136 #: src/cmd/info.c:137
#, c-format #, c-format
msgid "Desc " msgid "Desc "
msgstr "Desc " msgstr "Desc "
#: src/cmd/info.c:137 #: src/cmd/info.c:138
#, c-format #, c-format
msgid "Size " msgid "Size "
msgstr "Size " msgstr "Size "
#: src/cmd/info.c:140 #: src/cmd/info.c:141
#, c-format #, c-format
msgid "Depends " msgid "Depends "
msgstr "Depends " msgstr "Depends "
#: src/cmd/info.c:143 #: src/cmd/info.c:144
#, c-format #, c-format
msgid "Changes " msgid "Changes "
msgstr "Changes " msgstr "Changes "
#: src/cmd/info.c:146 #: src/cmd/info.c:147
#, fuzzy, c-format #, fuzzy, c-format
msgid "Pool " msgid "Pool "
msgstr " " msgstr " "
#: src/cmd/info.c:149 src/cmd/info.c:150 #: src/cmd/info.c:150 src/cmd/info.c:151
#, c-format #, c-format
msgid "Installed " msgid "Installed "
msgstr "Installed " msgstr "Installed "
#: src/cmd/info.c:153 src/cmd/info.c:154 #: src/cmd/info.c:154 src/cmd/info.c:155
#, c-format #, c-format
msgid "Up-to-date " msgid "Up-to-date "
msgstr "Up-to-date " msgstr "Up-to-date "
#: src/cmd/install.c:33 #: src/cmd/install.c:34
msgid "Listing options for the install command:" msgid "Listing options for the install command:"
msgstr "Listing options for the install command:" msgstr "Listing options for the install command:"
#: src/cmd/install.c:43 src/cmd/update.c:28 #: src/cmd/install.c:44 src/cmd/update.c:29
msgid "There are no avaliable pools, have you synced yet?" msgid "There are no avaliable pools, have you synced yet?"
msgstr "There are no avaliable pools, have you synced yet?" msgstr "There are no avaliable pools, have you synced yet?"
#: src/cmd/install.c:62 #: src/cmd/install.c:63
msgid "Specified " msgid "Specified "
msgstr "Specified " msgstr "Specified "
#: src/cmd/install.c:72 #: src/cmd/install.c:73
msgid "Failed to load " msgid "Failed to load "
msgstr "Failed to load " msgstr "Failed to load "
#: src/cmd/install.c:82 src/cmd/remove.c:54 #: src/cmd/install.c:83 src/cmd/remove.c:55
msgid "Failed to find " msgid "Failed to find "
msgstr "Failed to find " msgstr "Failed to find "
#: src/cmd/install.c:100 #: src/cmd/install.c:101
msgid "Failed to resolve " msgid "Failed to resolve "
msgstr "Failed to resolve " msgstr "Failed to resolve "
#: src/cmd/install.c:109 #: src/cmd/install.c:110
msgid "Nothing to do (no packages to install)" msgid "Nothing to do (no packages to install)"
msgstr "Nothing to do (no packages to install)" msgstr "Nothing to do (no packages to install)"
#: src/cmd/install.c:118 src/cmd/install.c:120 src/cmd/remove.c:74 #: src/cmd/install.c:119 src/cmd/install.c:121 src/cmd/remove.c:75
#: src/cmd/remove.c:76 src/cmd/update.c:49 src/cmd/update.c:51 #: src/cmd/remove.c:77 src/cmd/update.c:50 src/cmd/update.c:52
msgid "Following " msgid "Following "
msgstr "Following " msgstr "Following "
#: src/cmd/install.c:126 src/cmd/remove.c:83 #: src/cmd/install.c:127 src/cmd/remove.c:84
msgid "Total of " msgid "Total of "
msgstr "Total of " msgstr "Total of "
#: src/cmd/install.c:129 src/cmd/update.c:58 #: src/cmd/install.c:130 src/cmd/update.c:59
#, c-format #, c-format
msgid "Root directory is modified, install scripts will be saved in %s" msgid "Root directory is modified, install scripts will be saved in %s"
msgstr "Root directory is modified, install scripts will be saved in %s" msgstr "Root directory is modified, install scripts will be saved in %s"
#: src/cmd/install.c:131 src/cmd/remove.c:84 src/cmd/update.c:60 #: src/cmd/install.c:132 src/cmd/remove.c:85 src/cmd/update.c:61
msgid "Continue?" msgid "Continue?"
msgstr "Continue?" msgstr "Continue?"
#: src/cmd/install.c:132 src/cmd/remove.c:85 src/cmd/update.c:61 #: src/cmd/install.c:133 src/cmd/remove.c:86 src/cmd/update.c:62
msgid "Operation cancelled" msgid "Operation cancelled"
msgstr "Operation cancelled" msgstr "Operation cancelled"
#: src/cmd/install.c:148 src/cmd/install.c:152 src/cmd/install.c:172 #: src/cmd/install.c:149 src/cmd/install.c:153 src/cmd/install.c:173
#: src/cmd/install.c:188 src/cmd/remove.c:92 src/cmd/update.c:71 #: src/cmd/install.c:189 src/cmd/remove.c:93 src/cmd/update.c:72
#: src/cmd/update.c:82 src/cmd/update.c:93 #: src/cmd/update.c:83 src/cmd/update.c:94
msgid "(" msgid "("
msgstr "(" msgstr "("
#: src/cmd/install.c:158 src/cmd/update.c:77 #: src/cmd/install.c:159 src/cmd/update.c:78
msgid "Failed to download " msgid "Failed to download "
msgstr "Failed to download " msgstr "Failed to download "
#: src/cmd/install.c:179 src/cmd/remove.c:99 src/cmd/update.c:88 #: src/cmd/install.c:180 src/cmd/remove.c:100 src/cmd/update.c:89
msgid "Failed to remove " msgid "Failed to remove "
msgstr "Failed to remove " msgstr "Failed to remove "
#: src/cmd/install.c:195 src/cmd/update.c:99 #: src/cmd/install.c:196 src/cmd/update.c:100
msgid "Failed to install " msgid "Failed to install "
msgstr "Failed to install " msgstr "Failed to install "
#: src/cmd/install.c:202 #: src/cmd/install.c:203
msgid "Installed " msgid "Installed "
msgstr "Installed " msgstr "Installed "
#: src/cmd/install.c:202 #: src/cmd/install.c:203
msgid "Installed all of the " msgid "Installed all of the "
msgstr "Installed all of the " msgstr "Installed all of the "
#: src/cmd/list.c:38 #: src/cmd/list.c:39
#, fuzzy #, fuzzy
msgid "There are no installed packages" msgid "There are no installed packages"
msgstr "There no installed packages" msgstr "There no installed packages"
#: src/cmd/list.c:43 #: src/cmd/list.c:44
msgid "Listing " msgid "Listing "
msgstr "Listing " msgstr "Listing "
#: src/cmd/remove.c:27 #: src/cmd/remove.c:28
msgid "Listing options for the remove command:" msgid "Listing options for the remove command:"
msgstr "Listing options for the remove command:" msgstr "Listing options for the remove command:"
#: src/cmd/remove.c:59 #: src/cmd/remove.c:60
#, fuzzy #, fuzzy
msgid "Cannot remove " msgid "Cannot remove "
msgstr "Failed to remove " msgstr "Failed to remove "
#: src/cmd/remove.c:67 #: src/cmd/remove.c:68
msgid "Nothing to do (no packages to remove)" msgid "Nothing to do (no packages to remove)"
msgstr "Nothing to do (no packages to remove)" msgstr "Nothing to do (no packages to remove)"
#: src/cmd/remove.c:106 #: src/cmd/remove.c:107
msgid "Removed " msgid "Removed "
msgstr "Removed " msgstr "Removed "
#: src/cmd/remove.c:106 #: src/cmd/remove.c:107
msgid "Removed all of the " msgid "Removed all of the "
msgstr "Removed all of the " msgstr "Removed all of the "
#: src/cmd/search.c:49 src/cmd/search.c:120 #: src/cmd/search.c:72 src/cmd/search.c:149
msgid "No results" msgid "No results, maybe you forgot to sync?"
msgstr "" msgstr ""
#: src/cmd/search.c:54 src/cmd/search.c:125 #: src/cmd/search.c:77 src/cmd/search.c:154
msgid "Found " msgid "Found "
msgstr "" msgstr ""
#: src/cmd/search.c:90 #: src/cmd/search.c:113
#, fuzzy, c-format
msgid "Failed to load package pools: %s"
msgstr "Failed to get the package update list: %s"
#: src/cmd/search.c:119
#, fuzzy, c-format #, fuzzy, c-format
msgid "Failed to get package list: %s" msgid "Failed to get package list: %s"
msgstr "Failed to get the package update list: %s" msgstr "Failed to get the package update list: %s"
#: src/cmd/search.c:189 #: src/cmd/search.c:218
#, fuzzy #, fuzzy
msgid "Please specify only a single value for searching" msgid "Please specify only a single query for searching"
msgstr "Please specify only a single package name" msgstr "Please specify only a single package name"
#: src/cmd/search.c:196 #: src/cmd/search.c:225
#, fuzzy #, fuzzy
msgid "Please specify a value for searching" msgid "Please specify a query for searching"
msgstr "Please specify a single package" msgstr "Please specify a single package"
#: src/cmd/sync.c:20 #: src/cmd/sync.c:30
msgid "There are no pools specified in the configuration" msgid "There are no pools specified in the configuration"
msgstr "There are no pools specified in the configuration" msgstr "There are no pools specified in the configuration"
#: src/cmd/sync.c:28 #: src/cmd/sync.c:39
#, c-format #, c-format
msgid "Failed to sync pools: %s" msgid "Failed to sync pools: %s"
msgstr "Failed to sync pools: %s" msgstr "Failed to sync pools: %s"
#: src/cmd/update.c:22 #: src/cmd/update.c:23
msgid "Listing options for the update command:" msgid "Listing options for the update command:"
msgstr "Listing options for the update command:" msgstr "Listing options for the update command:"
#: src/cmd/update.c:39 #: src/cmd/update.c:40
#, c-format #, c-format
msgid "Failed to get the package update list: %s" msgid "Failed to get the package update list: %s"
msgstr "Failed to get the package update list: %s" msgstr "Failed to get the package update list: %s"
#: src/cmd/update.c:44 #: src/cmd/update.c:45
msgid "All packages are up-to-date" msgid "All packages are up-to-date"
msgstr "All packages are up-to-date" msgstr "All packages are up-to-date"
#: src/cmd/update.c:67 #: src/cmd/update.c:68
msgid "Failed to update " msgid "Failed to update "
msgstr "Failed to update " msgstr "Failed to update "

View File

@ -20,6 +20,8 @@ bool callback_remove(lm_ctx_t *ctx, lm_entry_t *ent, char *file, size_t current,
bool callback_sync( bool callback_sync(
lm_ctx_t *ctx, lm_pool_t *pool, lm_ctx_sync_state_t state, size_t current, size_t total, void *data) { lm_ctx_t *ctx, lm_pool_t *pool, lm_ctx_sync_state_t state, size_t current, size_t total, void *data) {
bool fail = *(bool *)data;
switch (state) { switch (state) {
case SYNC_DOWNLOADING_INFO: case SYNC_DOWNLOADING_INFO:
bar(current, total); bar(current, total);
@ -32,6 +34,8 @@ bool callback_sync(
case SYNC_INFO_FAIL: case SYNC_INFO_FAIL:
bar_free(); bar_free();
error(_("Failed to sync " FG_BOLD "%s" FG_RESET ": %s"), pool->name, lm_strerror()); error(_("Failed to sync " FG_BOLD "%s" FG_RESET ": %s"), pool->name, lm_strerror());
if (fail)
return false;
break; break;
case SYNC_DOWNLOADING_LIST: case SYNC_DOWNLOADING_LIST:
@ -47,6 +51,8 @@ bool callback_sync(
bar_free(); bar_free();
if (LM_ERR_InfoNotLoaded != lm_error()) if (LM_ERR_InfoNotLoaded != lm_error())
error(_("Failed to sync " FG_BOLD "%s" FG_RESET ": %s"), pool->name, lm_strerror()); error(_("Failed to sync " FG_BOLD "%s" FG_RESET ": %s"), pool->name, lm_strerror());
if (fail)
return false;
break; break;
} }

View File

@ -44,6 +44,7 @@ bool cmd_info(lm_ctx_t *ctx, config_t *config, args_t *args){
} }
if(args_get_bool(args, "help")){ if(args_get_bool(args, "help")){
info(_("Usage: " FG_BOLD "info <options> [package name]"));
info(_("Listing options for the list command:")); info(_("Listing options for the list command:"));
printf(_(" "FG_BOLD"--grep"FG_RESET":\tmakes the output \"grepable\"\n")); printf(_(" "FG_BOLD"--grep"FG_RESET":\tmakes the output \"grepable\"\n"));
printf(_(" "FG_BOLD"--changes"FG_RESET":\topen the changes file for the package\n")); printf(_(" "FG_BOLD"--changes"FG_RESET":\topen the changes file for the package\n"));

View File

@ -30,6 +30,7 @@ bool cmd_install(lm_ctx_t *ctx, config_t *config, args_t *args){
} }
if(args_get_bool(args, "help")){ if(args_get_bool(args, "help")){
info(_("Usage: " FG_BOLD "install <options> [package name(s)]"));
info(_("Listing options for the install command:")); info(_("Listing options for the install command:"));
printf(_(" "FG_BOLD"--ignore-depends"FG_RESET":\tignore package dependencies\n")); printf(_(" "FG_BOLD"--ignore-depends"FG_RESET":\tignore package dependencies\n"));
printf(_(" "FG_BOLD"--ignore-none"FG_RESET":\tignore if there is nothing do\n")); printf(_(" "FG_BOLD"--ignore-none"FG_RESET":\tignore if there is nothing do\n"));

View File

@ -20,6 +20,7 @@ bool cmd_list(lm_ctx_t *ctx, config_t *config, args_t *args){
} }
if(args_get_bool(args, "help")){ if(args_get_bool(args, "help")){
info(_("Usage: " FG_BOLD "list <options>"));
info(_("Listing options for the list command:")); info(_("Listing options for the list command:"));
printf(_(" "FG_BOLD"--grep"FG_RESET":\tmakes the output \"grepable\"\n")); printf(_(" "FG_BOLD"--grep"FG_RESET":\tmakes the output \"grepable\"\n"));
printf(_(" "FG_BOLD"--desc"FG_RESET":\tshow package descriptions\n")); printf(_(" "FG_BOLD"--desc"FG_RESET":\tshow package descriptions\n"));

View File

@ -24,6 +24,7 @@ bool cmd_remove(lm_ctx_t *ctx, config_t *config, args_t *args){
} }
if(args_get_bool(args, "help")){ if(args_get_bool(args, "help")){
info(_("Usage: " FG_BOLD "remove <options> [package name(s)]"));
info(_("Listing options for the remove command:")); info(_("Listing options for the remove command:"));
printf(_(" "FG_BOLD"--break"FG_RESET":\tbreak other package depends\n")); printf(_(" "FG_BOLD"--break"FG_RESET":\tbreak other package depends\n"));
printf(_(" "FG_BOLD"--yes"FG_RESET":\tdon't ask for confirmation\n")); printf(_(" "FG_BOLD"--yes"FG_RESET":\tdon't ask for confirmation\n"));

View File

@ -2,6 +2,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <ctype.h>
#include "../util.h" #include "../util.h"
#include "../intl.h" #include "../intl.h"
@ -14,7 +15,29 @@ enum field {
FIELD_VERSION = 2, FIELD_VERSION = 2,
}; };
bool cmd_search_database(lm_ctx_t *ctx, args_t *args, char *search, enum field field) { bool contains(char *string, char *search){
if(NULL == string || NULL == search)
return false;
size_t string_size = strlen(string);
size_t search_size = strlen(search);
size_t i = 0;
char string_lower[string_size+1];
char search_lower[search_size+1];
for(i = 0; i < string_size; i++)
string_lower[i] = tolower(string[i]);
string_lower[i] = 0;
for(i = 0; i < search_size; i++)
search_lower[i] = tolower(search[i]);
search_lower[i] = 0;
return strstr(string_lower, search_lower) != NULL;
}
bool cmd_search_database(lm_ctx_t *ctx, args_t *args, char *query, enum field field) {
lm_entry_t *list = malloc(sizeof(lm_entry_t)); lm_entry_t *list = malloc(sizeof(lm_entry_t));
char *selected = NULL; char *selected = NULL;
size_t indx = 0, i = 0; size_t indx = 0, i = 0;
@ -37,7 +60,7 @@ bool cmd_search_database(lm_ctx_t *ctx, args_t *args, char *search, enum field f
break; break;
} }
if(NULL == selected || strstr(selected, search) == NULL) if(!contains(selected, query))
continue; continue;
list = realloc(list, sizeof(lm_entry_t)*((++indx)+1)); list = realloc(list, sizeof(lm_entry_t)*((++indx)+1));
@ -46,7 +69,7 @@ bool cmd_search_database(lm_ctx_t *ctx, args_t *args, char *search, enum field f
if(indx <= 0){ if(indx <= 0){
if(!args_get_bool(args, "grep")) if(!args_get_bool(args, "grep"))
info(_("No results")); info(_("No results, maybe you forgot to sync?"));
goto end; goto end;
} }
@ -76,7 +99,7 @@ end:
return ret; return ret;
} }
bool cmd_search_pools(lm_ctx_t *ctx, args_t *args, char *search, enum field field) { bool cmd_search_pools(lm_ctx_t *ctx, args_t *args, char *query, enum field field) {
lm_pkg_t **list = malloc(sizeof(lm_pkg_t*)); lm_pkg_t **list = malloc(sizeof(lm_pkg_t*));
char *selected = NULL; char *selected = NULL;
size_t indx = 0, i = 0; size_t indx = 0, i = 0;
@ -84,6 +107,12 @@ bool cmd_search_pools(lm_ctx_t *ctx, args_t *args, char *search, enum field fiel
bool ret = false; bool ret = false;
list[indx] = NULL; list[indx] = NULL;
if(!lm_ctx_sync(ctx, false, NULL, NULL)){
if(!args_get_bool(args, "grep"))
info(_("Failed to load package pools: %s"), lm_strerror());
goto end;
}
if(!lm_ctx_list(ctx, &plist)){ if(!lm_ctx_list(ctx, &plist)){
if(!args_get_bool(args, "grep")) if(!args_get_bool(args, "grep"))
@ -108,7 +137,7 @@ bool cmd_search_pools(lm_ctx_t *ctx, args_t *args, char *search, enum field fiel
break; break;
} }
if(NULL == selected || strstr(selected, search) == NULL) if(!contains(selected, query))
continue; continue;
list = realloc(list, sizeof(lm_pkg_t*)*((++indx)+1)); list = realloc(list, sizeof(lm_pkg_t*)*((++indx)+1));
@ -117,7 +146,7 @@ bool cmd_search_pools(lm_ctx_t *ctx, args_t *args, char *search, enum field fiel
if(indx <= 0){ if(indx <= 0){
if(!args_get_bool(args, "grep")) if(!args_get_bool(args, "grep"))
info(_("No results")); info(_("No results, maybe you forgot to sync?"));
goto end; goto end;
} }
@ -152,7 +181,6 @@ bool cmd_search(lm_ctx_t *ctx, config_t *config, args_t *args){
args_split(args, "grep"); args_split(args, "grep");
args_split(args, "desc"); args_split(args, "desc");
args_split(args, "field");
args_split(args, "database"); args_split(args, "database");
args_register(args, "grep"); args_register(args, "grep");
@ -166,6 +194,7 @@ bool cmd_search(lm_ctx_t *ctx, config_t *config, args_t *args){
} }
if(args_get_bool(args, "help")){ if(args_get_bool(args, "help")){
info(_("Usage: " FG_BOLD "search <options> [query]"));
info(_("Listing options for the list command:")); info(_("Listing options for the list command:"));
printf(_(" "FG_BOLD"--grep"FG_RESET":\tmakes the output \"grepable\"\n")); printf(_(" "FG_BOLD"--grep"FG_RESET":\tmakes the output \"grepable\"\n"));
printf(_(" "FG_BOLD"--desc"FG_RESET":\tshow package description of the results\n")); printf(_(" "FG_BOLD"--desc"FG_RESET":\tshow package description of the results\n"));
@ -175,25 +204,25 @@ bool cmd_search(lm_ctx_t *ctx, config_t *config, args_t *args){
} }
enum field field = FIELD_NAME; enum field field = FIELD_NAME;
char *search = NULL, *field_val = NULL; char *query = NULL, *field_val = NULL;
for(size_t i = 1; i < args->count; i++){ for(size_t i = 1; i < args->count; i++){
if(NULL != args->list[i].name) if(NULL != args->list[i].name)
continue; continue;
if(NULL == search && NULL != (search = args->list[i].value)) if(NULL == query && NULL != (query = args->list[i].value))
continue; continue;
else if(NULL != search && NULL != (search = args->list[i].value)){ else if(NULL != query && NULL != (query = args->list[i].value)){
if(!args_get_bool(args, "grep")) if(!args_get_bool(args, "grep"))
error(_("Please specify only a single value for searching")); error(_("Please specify only a single query for searching"));
return false; return false;
} }
} }
if(NULL == search){ if(NULL == query){
if(!args_get_bool(args, "grep")) if(!args_get_bool(args, "grep"))
error(_("Please specify a value for searching")); error(_("Please specify a query for searching"));
return false; return false;
} }
@ -205,7 +234,7 @@ bool cmd_search(lm_ctx_t *ctx, config_t *config, args_t *args){
field = FIELD_VERSION; field = FIELD_VERSION;
if(args_get_bool(args, "database")) if(args_get_bool(args, "database"))
return cmd_search_database(ctx, args, search, field); return cmd_search_database(ctx, args, query, field);
return cmd_search_pools(ctx, args, search, field); return cmd_search_pools(ctx, args, query, field);
} }

View File

@ -7,29 +7,43 @@
#include "../log.h" #include "../log.h"
bool cmd_sync(lm_ctx_t *ctx, config_t *config, args_t *args){ bool cmd_sync(lm_ctx_t *ctx, config_t *config, args_t *args){
size_t sycned = 0; bool ret = false, fail = false;
bool ret = false; ssize_t synced = 0;
char *arg = NULL; char *arg = NULL;
args_split(args, "fail");
args_register(args, "fail");
if((arg = args_register_check(args)) != NULL){ if((arg = args_register_check(args)) != NULL){
error(_("Unknown argument: "FG_BOLD"--%s"FG_RESET", run with "FG_BOLD"--help"FG_RESET" to list the avaliable arguments"), arg); error(_("Unknown argument: "FG_BOLD"--%s"FG_RESET", run with "FG_BOLD"--help"FG_RESET" to list the avaliable arguments"), arg);
return false; return false;
} }
if(args_get_bool(args, "help")){
info(_("Usage: " FG_BOLD "sync <options>"));
info(_("Listing options for the list command:"));
printf(_(" "FG_BOLD"--fail"FG_RESET":\tquit on a single pool sync failure\n"));
return true;
}
if(config->pool_count == 0){ if(config->pool_count == 0){
error(_("There are no pools specified in the configuration")); error(_("There are no pools specified in the configuration"));
goto end; goto end;
} }
sycned = lm_ctx_sync(ctx, true, callback_sync, NULL); fail = args_get_bool(args, "fail");
synced = lm_ctx_sync(ctx, true, callback_sync, &fail);
bar_free(); bar_free();
if(sycned < 0){ if(synced < 0 && !fail){
error(_("Failed to sync pools: %s"), lm_strerror()); error(_("Failed to sync pools: %s"), lm_strerror());
goto end; goto end;
} }
info(_("Synced "FG_BOLD"%d"FG_RESET"/"FG_BOLD"%d"FG_RESET" pools"), sycned, config->pool_count); else if(synced < 0 && fail)
goto end;
info(_("Synced "FG_BOLD"%d"FG_RESET"/"FG_BOLD"%d"FG_RESET" pools"), synced, config->pool_count);
ret = true; ret = true;
end: end:

View File

@ -19,6 +19,7 @@ bool cmd_update(lm_ctx_t *ctx, config_t *config, args_t *args){
} }
if(args_get_bool(args, "help")){ if(args_get_bool(args, "help")){
info(_("Usage: " FG_BOLD "update <options>"));
info(_("Listing options for the update command:")); info(_("Listing options for the update command:"));
printf(_(" "FG_BOLD"--yes"FG_RESET":\tdon't ask for confirmation\n")); printf(_(" "FG_BOLD"--yes"FG_RESET":\tdon't ask for confirmation\n"));
return true; return true;

View File

@ -198,7 +198,8 @@ help:
printf( printf(
_(" " FG_BOLD "--config" FG_RESET ":\t specify the configuration file (default is /etc/matt/config.ini)\n")); _(" " FG_BOLD "--config" FG_RESET ":\t specify the configuration file (default is /etc/matt/config.ini)\n"));
printf(_(" " FG_BOLD "--root" FG_RESET ":\t specify a custom root directory (default is /)\n\n")); printf(_(" " FG_BOLD "--root" FG_RESET ":\t specify a custom root directory (default is /)\n"));
printf(_(" " FG_BOLD "--help" FG_RESET ":\t list avaliable options/commands\n\n"));
info(_("Licensed under GPLv3, see https://www.gnu.org/licenses/ for more information")); info(_("Licensed under GPLv3, see https://www.gnu.org/licenses/ for more information"));