search: add optional --quiet parameter
PATCH 1/1 search: add optional --quiet parameter
From: Daniel Drake <[email protected]>
Currently when you search for a file, if no result is found it prints an error message.
That's not ideal when the file is optional, so add a --quiet arg to silence this.
--- grub-core/commands/search.c | 6 +++--- grub-core/commands/search_wrap.c | 8 +++++--- include/grub/search.h | 6 +++--- 3 files changed, 11 insertions(+), 9 deletions(-)
grub-core/commands/search.c +3 -3
@@ -261,7 +261,7 @@ try (struct search_ctx *ctx) }void -FUNC_NAME (const char *key,const char *var,int no_floppy, +FUNC_NAME (const char *key,const char *var,int no_floppy,int quiet,char **hints,unsigned nhints) {struct search_ctx ctx = {
@@ -292,7 +292,7 @@ FUNC_NAME (const char *key, const char *var, int no_floppy,else try (&ctx); -if (grub_errno ==GRUB_ERR_NONE && ctx.count ==0 ) +if (!quiet && grub_errno ==GRUB_ERR_NONE && ctx.count ==0 )grub_error (GRUB_ERR_FILE_NOT_FOUND ,"no such device: %s" , key); }
@@ -303,7 +303,7 @@ grub_cmd_do_search (grub_command_t cmd __attribute__ ((unused)), int argc,if (argc ==0 )return grub_error (GRUB_ERR_BAD_ARGUMENT ,N_ ("one argument expected" )); -FUNC_NAME (args[0 ], argc ==1 ?0 : args[1 ],0 , (args +2 ), +FUNC_NAME (args[0 ], argc ==1 ?0 : args[1 ],0 ,0 , (args +2 ), argc >2 ? argc -2 :0 );return grub_errno;
grub-core/commands/search_wrap.c +5 -3
@@ -40,6 +40,7 @@ static const struct grub_arg_option options[] =N_ ("Set a variable to the first device found." ),N_ ("VARNAME" ), ARG_TYPE_STRING}, {"no-floppy", 'n', 0, N_("Do not probe any floppy drive."), 0, 0}, + {"quiet", 'q', 0, N_("Don't print error if no match."), 0, 0}, {"hint", 'h', GRUB_ARG_OPTION_REPEATABLE,N_ ("First try the device HINT. If HINT ends in comma, " "also try subpartitions"), N_("HINT"), ARG_TYPE_STRING},
@@ -73,6 +74,7 @@ enum optionsSEARCH_FS_UUID ,SEARCH_SET ,SEARCH_NO_FLOPPY , +SEARCH_QUIET ,SEARCH_HINT ,SEARCH_HINT_IEEE1275 , SEARCH_HINT_BIOS,
@@ -182,13 +184,13 @@ grub_cmd_search (grub_extcmd_context_t ctxt, int argc, char **args)if (state[SEARCH_LABEL ].set)grub_search_label (id, var, state[SEARCH_NO_FLOPPY ].set, - hints, nhints); + state[SEARCH_QUIET ].set, hints, nhints);else if (state[SEARCH_FS_UUID ].set)grub_search_fs_uuid (id, var, state[SEARCH_NO_FLOPPY ].set, - hints, nhints); + state[SEARCH_QUIET ].set, hints, nhints);else if (state[SEARCH_FILE ].set)grub_search_fs_file (id, var, state[SEARCH_NO_FLOPPY ].set, - hints, nhints); + state[SEARCH_QUIET ].set, hints, nhints);else grub_error (GRUB_ERR_INVALID_COMMAND ,"unspecified search type" );
include/grub/search.h +3 -3
@@ -20,10 +20,10 @@#define GRUB_SEARCH_HEADER 1void grub_search_fs_file (const char *key,const char *var,int no_floppy, -char **hints,unsigned nhints); +int quiet,char **hints,unsigned nhints);void grub_search_fs_uuid (const char *key,const char *var,int no_floppy, -char **hints,unsigned nhints); +int quiet,char **hints,unsigned nhints);void grub_search_label (const char *key,const char *var,int no_floppy, -char **hints,unsigned nhints); +int quiet,char **hints,unsigned nhints);#endif
Signature · 1 line
2.14.1