From c7d969395f59dab377101361d90f4377e5a8af50 Mon Sep 17 00:00:00 2001 From: ngn Date: Mon, 12 Aug 2024 03:53:57 +0300 Subject: [PATCH] new: print unknown arguments --- locale/tr/LC_MESSAGES/matt.po | 145 ++++++++++++++++++---------------- src/args.c | 24 +++++- src/args.h | 3 + src/cmd/info.c | 11 +++ src/cmd/install.c | 11 +++ src/cmd/list.c | 10 +++ src/cmd/remove.c | 10 +++ src/cmd/sync.c | 6 ++ src/cmd/update.c | 8 ++ src/main.c | 3 + 10 files changed, 157 insertions(+), 74 deletions(-) diff --git a/locale/tr/LC_MESSAGES/matt.po b/locale/tr/LC_MESSAGES/matt.po index 6944a4f..fea4776 100644 --- a/locale/tr/LC_MESSAGES/matt.po +++ b/locale/tr/LC_MESSAGES/matt.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-08-11 01:49+0300\n" +"POT-Creation-Date: 2024-08-12 03:53+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -73,76 +73,76 @@ msgstr "Please answer with y/n" msgid "Received a segfault" msgstr "Received a segfault" -#: src/main.c:97 +#: src/main.c:100 msgid "Failed to access the root directory, are you running as root?" msgstr "Failed to access the root directory, are you running as root?" -#: src/main.c:101 +#: src/main.c:104 #, fuzzy msgid "Failed to access the data directory (" msgstr "Failed to access the configuration file: %s" -#: src/main.c:105 +#: src/main.c:108 #, fuzzy msgid "Failed to access the temp directory (" msgstr "Failed to open the editor: %s" -#: src/main.c:109 +#: src/main.c:112 #, fuzzy, c-format msgid "Failed to initialize libmp context: %s" msgstr "Failed to install " -#: src/main.c:120 +#: src/main.c:123 #, fuzzy msgid "Failed to create the pools directory (" msgstr "Failed to open the editor: %s" -#: src/main.c:130 +#: src/main.c:133 msgid "Failed to add pool " msgstr "Failed to add pool " -#: src/main.c:144 +#: src/main.c:147 msgid "Failed to lock, matt is already running" msgstr "Failed to lock, matt is already running" -#: src/main.c:148 +#: src/main.c:151 msgid "Failed to lock, are you root?" msgstr "Failed to lock, are you root?" -#: src/main.c:159 +#: src/main.c:162 msgid "Command not found: " msgstr "Command not found: " -#: src/main.c:161 +#: src/main.c:164 #, fuzzy, c-format msgid "MatterLinux package manager %s (libmp %s)" msgstr "MatterLinux package manager (version %s)" -#: src/main.c:162 +#: src/main.c:165 msgid "Usage: " msgstr "Usage: " -#: src/main.c:164 +#: src/main.c:167 msgid "Here is a list of available commands:" msgstr "Here is a list of available commands:" -#: src/main.c:170 +#: src/main.c:173 msgid "To list different options, use commands with " msgstr "To list different options, use commands with " -#: src/main.c:171 +#: src/main.c:174 msgid "Here is a list of available global options:" msgstr "Here is a list of available global options:" -#: src/main.c:174 src/main.c:175 src/cmd/info.c:43 src/cmd/info.c:44 -#: src/cmd/info.c:45 src/cmd/install.c:32 src/cmd/install.c:33 -#: src/cmd/install.c:34 src/cmd/list.c:14 src/cmd/list.c:15 src/cmd/remove.c:21 -#: src/cmd/remove.c:22 src/cmd/update.c:30 +#: src/main.c:177 src/main.c:178 src/cmd/info.c:54 src/cmd/info.c:55 +#: src/cmd/info.c:56 src/cmd/install.c:43 src/cmd/install.c:44 +#: src/cmd/install.c:45 src/cmd/list.c:24 src/cmd/list.c:25 src/cmd/remove.c:31 +#: src/cmd/remove.c:32 src/cmd/update.c:38 #, c-format msgid " " msgstr " " -#: src/main.c:177 +#: src/main.c:180 msgid "" "Licensed under GPLv3, see https://www.gnu.org/licenses/ for more information" msgstr "" @@ -162,176 +162,181 @@ msgstr "Failed to run the editor: %s" msgid "Failed to open the editor: %s" msgstr "Failed to open the editor: %s" -#: src/cmd/info.c:19 src/cmd/info.c:29 src/cmd/install.c:87 src/cmd/remove.c:43 +#: src/cmd/info.c:19 src/cmd/info.c:29 src/cmd/install.c:98 src/cmd/remove.c:53 msgid "Package " msgstr "Package " -#: src/cmd/info.c:42 src/cmd/list.c:13 +#: src/cmd/info.c:48 src/cmd/install.c:37 src/cmd/list.c:18 src/cmd/remove.c:25 +#: src/cmd/sync.c:48 src/cmd/update.c:32 +msgid "Unknown argument: " +msgstr "" + +#: src/cmd/info.c:53 src/cmd/list.c:23 msgid "Listing options for the list command:" msgstr "Listing options for the list command:" -#: src/cmd/info.c:65 +#: src/cmd/info.c:76 msgid "Please specify only a single package name" msgstr "Please specify only a single package name" -#: src/cmd/info.c:72 +#: src/cmd/info.c:83 msgid "Please specify a single package" msgstr "Please specify a single package" -#: src/cmd/info.c:87 +#: src/cmd/info.c:98 msgid "Failed to get the changes file for " msgstr "Failed to get the changes file for " -#: src/cmd/info.c:93 +#: src/cmd/info.c:104 msgid "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:100 +#: src/cmd/info.c:111 msgid "Failed to get the depends list for " msgstr "Failed to get the depends list for " -#: src/cmd/info.c:127 +#: src/cmd/info.c:138 #, c-format msgid "Name " msgstr "Name " -#: src/cmd/info.c:128 +#: src/cmd/info.c:139 #, c-format msgid "Version " msgstr "Version " -#: src/cmd/info.c:129 +#: src/cmd/info.c:140 #, c-format msgid "Desc " msgstr "Desc " -#: src/cmd/info.c:130 +#: src/cmd/info.c:141 #, c-format msgid "Size " msgstr "Size " -#: src/cmd/info.c:133 +#: src/cmd/info.c:144 #, c-format msgid "Depends " msgstr "Depends " -#: src/cmd/info.c:136 +#: src/cmd/info.c:147 #, c-format msgid "Changes " msgstr "Changes " -#: src/cmd/info.c:140 src/cmd/info.c:141 +#: src/cmd/info.c:151 src/cmd/info.c:152 #, c-format msgid "Installed " msgstr "Installed " -#: src/cmd/info.c:143 src/cmd/info.c:144 +#: src/cmd/info.c:154 src/cmd/info.c:155 #, c-format msgid "Up-to-date " msgstr "Up-to-date " -#: src/cmd/install.c:31 +#: src/cmd/install.c:42 msgid "Listing options for the install command:" msgstr "Listing options for the install command:" -#: src/cmd/install.c:39 src/cmd/update.c:35 +#: src/cmd/install.c:50 src/cmd/update.c:43 msgid "There are no avaliable pools, have you synced yet?" msgstr "There are no avaliable pools, have you synced yet?" -#: src/cmd/install.c:58 +#: src/cmd/install.c:69 msgid "Specified " msgstr "" -#: src/cmd/install.c:68 +#: src/cmd/install.c:79 #, fuzzy msgid "Failed to load " msgstr "Failed to download " -#: src/cmd/install.c:78 src/cmd/remove.c:45 +#: src/cmd/install.c:89 src/cmd/remove.c:55 msgid "Failed to find " msgstr "Failed to find " -#: src/cmd/install.c:93 +#: src/cmd/install.c:104 msgid "Failed to resolve " msgstr "Failed to resolve " -#: src/cmd/install.c:99 +#: src/cmd/install.c:110 msgid "Nothing to do (no packages to install)" msgstr "Nothing to do (no packages to install)" -#: src/cmd/install.c:108 src/cmd/install.c:110 src/cmd/remove.c:65 -#: src/cmd/remove.c:67 src/cmd/update.c:56 src/cmd/update.c:58 +#: src/cmd/install.c:119 src/cmd/install.c:121 src/cmd/remove.c:75 +#: src/cmd/remove.c:77 src/cmd/update.c:64 src/cmd/update.c:66 msgid "Following " msgstr "Following " -#: src/cmd/install.c:116 src/cmd/remove.c:74 +#: src/cmd/install.c:127 src/cmd/remove.c:84 msgid "Total of " msgstr "Total of " -#: src/cmd/install.c:119 src/cmd/update.c:65 +#: src/cmd/install.c:130 src/cmd/update.c:73 #, c-format msgid "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:121 src/cmd/remove.c:75 src/cmd/update.c:67 +#: src/cmd/install.c:132 src/cmd/remove.c:85 src/cmd/update.c:75 msgid "Continue?" msgstr "Continue?" -#: src/cmd/install.c:122 src/cmd/remove.c:76 src/cmd/update.c:68 +#: src/cmd/install.c:133 src/cmd/remove.c:86 src/cmd/update.c:76 msgid "Operation cancelled" msgstr "Operation cancelled" -#: src/cmd/install.c:138 src/cmd/install.c:142 src/cmd/install.c:157 -#: src/cmd/remove.c:83 src/cmd/update.c:78 src/cmd/update.c:87 -#: src/cmd/update.c:96 +#: src/cmd/install.c:149 src/cmd/install.c:153 src/cmd/install.c:168 +#: src/cmd/remove.c:93 src/cmd/update.c:86 src/cmd/update.c:95 +#: src/cmd/update.c:104 msgid "(" msgstr "(" -#: src/cmd/install.c:148 src/cmd/update.c:83 +#: src/cmd/install.c:159 src/cmd/update.c:91 msgid "Failed to download " msgstr "Failed to download " -#: src/cmd/install.c:163 src/cmd/update.c:101 +#: src/cmd/install.c:174 src/cmd/update.c:109 msgid "Failed to install " msgstr "Failed to install " -#: src/cmd/install.c:169 +#: src/cmd/install.c:180 msgid "Installed " msgstr "Installed " -#: src/cmd/install.c:169 +#: src/cmd/install.c:180 msgid "Installed all of the " msgstr "Installed all of the " -#: src/cmd/list.c:28 +#: src/cmd/list.c:38 msgid "There no installed packages" msgstr "There no installed packages" -#: src/cmd/list.c:33 +#: src/cmd/list.c:43 msgid "Listing " msgstr "Listing " -#: src/cmd/remove.c:20 +#: src/cmd/remove.c:30 msgid "Listing options for the remove command:" msgstr "Listing options for the remove command:" -#: src/cmd/remove.c:50 +#: src/cmd/remove.c:60 msgid "Cannot remove " msgstr "Cannot remove " -#: src/cmd/remove.c:58 +#: src/cmd/remove.c:68 msgid "Nothing to do (no packages to remove)" msgstr "Nothing to do (no packages to remove)" -#: src/cmd/remove.c:89 src/cmd/update.c:92 +#: src/cmd/remove.c:99 src/cmd/update.c:100 msgid "Failed to remove " msgstr "Failed to remove " -#: src/cmd/remove.c:95 +#: src/cmd/remove.c:105 msgid "Removed " msgstr "Removed " -#: src/cmd/remove.c:95 +#: src/cmd/remove.c:105 msgid "Removed all of the " msgstr "Removed all of the " @@ -339,33 +344,33 @@ msgstr "Removed all of the " msgid "Failed to sync " msgstr "Failed to sync " -#: src/cmd/sync.c:29 src/cmd/sync.c:59 +#: src/cmd/sync.c:29 src/cmd/sync.c:65 msgid "Synced " msgstr "Synced " -#: src/cmd/sync.c:47 +#: src/cmd/sync.c:53 msgid "There are no pools specified in the configuration" msgstr "There are no pools specified in the configuration" -#: src/cmd/sync.c:55 +#: src/cmd/sync.c:61 #, c-format msgid "Failed to sync pools: %s" msgstr "Failed to sync pools: %s" -#: src/cmd/update.c:29 +#: src/cmd/update.c:37 msgid "Listing options for the update command:" msgstr "Listing options for the update command:" -#: src/cmd/update.c:46 +#: src/cmd/update.c:54 #, c-format msgid "Failed to get the package update list: %s" msgstr "Failed to get the package update list: %s" -#: src/cmd/update.c:51 +#: src/cmd/update.c:59 msgid "All packages are up-to-date" msgstr "All packages are up-to-date" -#: src/cmd/update.c:74 +#: src/cmd/update.c:82 msgid "Failed to update " msgstr "Failed to update " diff --git a/src/args.c b/src/args.c index 9633a70..d80dcbd 100644 --- a/src/args.c +++ b/src/args.c @@ -7,14 +7,29 @@ #include "args.h" #include "util.h" +void args_register(args_t *args, char *name) { + for (int i = 0; i < args->count; i++) { + if (args->list[i].name != NULL && eq(args->list[i].name, name)) + args->list[i].registered = true; + } +} + +char *args_register_check(args_t *args) { + for (int i = 0; i < args->count; i++) + if (!args->list[i].registered) + return args->list[i].name; + return NULL; +} + void args_add_name(args_t *args, char *name) { if (NULL == args->list) args->list = malloc(sizeof(arg_t) * (args->count + 1)); else args->list = realloc(args->list, sizeof(arg_t) * (args->count + 1)); - args->list[args->count].name = name; - args->list[args->count++].value = NULL; + args->list[args->count].name = name; + args->list[args->count].registered = false; + args->list[args->count++].value = NULL; } void args_add_value(args_t *args, char *value) { @@ -23,8 +38,9 @@ void args_add_value(args_t *args, char *value) { else args->list = realloc(args->list, sizeof(arg_t) * (args->count + 1)); - args->list[args->count].name = NULL; - args->list[args->count++].value = value; + args->list[args->count].name = NULL; + args->list[args->count].registered = true; + args->list[args->count++].value = value; } void args_set_value(args_t *args, char *value) { diff --git a/src/args.h b/src/args.h index bb74276..56defd6 100644 --- a/src/args.h +++ b/src/args.h @@ -4,6 +4,7 @@ typedef struct arg { char *name; char *value; + bool registered; } arg_t; typedef struct args { @@ -11,6 +12,8 @@ typedef struct args { size_t count; } args_t; +void args_register(args_t *args, char *name); +char *args_register_check(args_t *args); args_t *args_parse(int argc, char *argv[]); char *args_get_string(args_t *args, char *name); bool args_get_bool(args_t *args, char *name); diff --git a/src/cmd/info.c b/src/cmd/info.c index aba3927..16ea179 100644 --- a/src/cmd/info.c +++ b/src/cmd/info.c @@ -34,10 +34,21 @@ lm_pkg_data_t *cmd_info_from_database(lm_ctx_t *ctx, lm_entry_t *entry, args_t * } bool cmd_info(lm_ctx_t *ctx, config_t *config, args_t *args){ + char *arg = NULL; + args_split(args, "grep"); args_split(args, "changes"); args_split(args, "database"); + args_register(args, "grep"); + args_register(args, "changes"); + args_register(args, "database"); + + 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); + return false; + } + if(args_get_bool(args, "help")){ info(_("Listing options for the list command:")); printf(_(" "FG_BOLD"--grep"FG_RESET":\tmakes the output \"grepable\"\n")); diff --git a/src/cmd/install.c b/src/cmd/install.c index b4b4e74..a0c473d 100644 --- a/src/cmd/install.c +++ b/src/cmd/install.c @@ -23,10 +23,21 @@ bool cmd_download_callback(lm_ctx_t *ctx, lm_pkg_t *pkg, bool is_archive, size_t } bool cmd_install(lm_ctx_t *ctx, config_t *config, args_t *args){ + char *arg = NULL; + args_split(args, "ignore-depends"); args_split(args, "continue"); args_split(args, "yes"); + args_register(args, "ignore-depends"); + args_register(args, "continue"); + args_register(args, "yes"); + + 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); + return false; + } + if(args_get_bool(args, "help")){ info(_("Listing options for the install command:")); printf(_(" "FG_BOLD"--ignore-depends"FG_RESET":\tignore package dependencies\n")); diff --git a/src/cmd/list.c b/src/cmd/list.c index cccc4d3..0b0c13a 100644 --- a/src/cmd/list.c +++ b/src/cmd/list.c @@ -6,9 +6,19 @@ #include "../log.h" bool cmd_list(lm_ctx_t *ctx, config_t *config, args_t *args){ + char *arg = NULL; + args_split(args, "grep"); args_split(args, "desc"); + args_register(args, "grep"); + args_register(args, "desc"); + + 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); + return false; + } + if(args_get_bool(args, "help")){ info(_("Listing options for the list command:")); printf(_(" "FG_BOLD"--grep"FG_RESET":\tmakes the output \"grepable\"\n")); diff --git a/src/cmd/remove.c b/src/cmd/remove.c index be76e62..8f89600 100644 --- a/src/cmd/remove.c +++ b/src/cmd/remove.c @@ -13,9 +13,19 @@ bool cmd_remove_callback(lm_ctx_t *ctx, lm_entry_t *ent, char *file, size_t curr } bool cmd_remove(lm_ctx_t *ctx, config_t *config, args_t *args){ + char *arg = NULL; + args_split(args, "break"); args_split(args, "yes"); + args_register(args, "break"); + args_register(args, "yes"); + + 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); + return false; + } + if(args_get_bool(args, "help")){ info(_("Listing options for the remove command:")); printf(_(" "FG_BOLD"--break"FG_RESET":\tbreak other package depends\n")); diff --git a/src/cmd/sync.c b/src/cmd/sync.c index 0140961..1dbb464 100644 --- a/src/cmd/sync.c +++ b/src/cmd/sync.c @@ -42,6 +42,12 @@ bool cmd_sync_callback(lm_ctx_t *ctx, lm_pool_t *pool, lm_ctx_sync_state_t state bool cmd_sync(lm_ctx_t *ctx, config_t *config, args_t *args){ size_t sycned = 0; bool ret = false; + char *arg = 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); + return false; + } if(config->pool_count == 0){ error(_("There are no pools specified in the configuration")); diff --git a/src/cmd/update.c b/src/cmd/update.c index cdabecc..7fb8edb 100644 --- a/src/cmd/update.c +++ b/src/cmd/update.c @@ -23,7 +23,15 @@ bool cmd_update_download_callback(lm_ctx_t *ctx, lm_pkg_t *pkg, bool is_archive, } bool cmd_update(lm_ctx_t *ctx, config_t *config, args_t *args){ + char *arg = NULL; + args_split(args, "yes"); + args_register(args, "yes"); + + 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); + return false; + } if(args_get_bool(args, "help")){ info(_("Listing options for the update command:")); diff --git a/src/main.c b/src/main.c index fc31c71..c33671b 100644 --- a/src/main.c +++ b/src/main.c @@ -75,6 +75,9 @@ int main(int argc, char *argv[], char *envp[]) { set_env(envp); lm_ctx_init(&ctx); args = args_parse(argc, argv); + args_register(args, "config"); + args_register(args, "root"); + args_register(args, "help"); if ((config_file = args_get_string(args, "config")) == NULL) config_file = "/etc/matt/config.ini";