diff mbox series

Consolidate error and help messages

Message ID 20200610075717.9385-1-christian.storm@siemens.com
State Accepted
Headers show
Series Consolidate error and help messages | expand

Commit Message

Christian Storm June 10, 2020, 7:57 a.m. UTC
Consolidate --help text to use stdout instead of stderr and
prefix error messages (on stderr) with "Error: " for better
readability.

To the same end, remove the subsequent usage() output for
some errors as this may be misguiding to a syntax error
while it wasn't.

Signed-off-by: Christian Storm <christian.storm@siemens.com>
---
 core/swupdate.c            | 26 ++++++++++++--------------
 suricatta/server_general.c |  2 +-
 suricatta/server_hawkbit.c |  2 +-
 suricatta/suricatta.c      |  2 +-
 4 files changed, 15 insertions(+), 17 deletions(-)

Comments

Stefano Babic June 10, 2020, 10:33 a.m. UTC | #1
On 10.06.20 09:57, Christian Storm wrote:
> Consolidate --help text to use stdout instead of stderr and
> prefix error messages (on stderr) with "Error: " for better
> readability.
> 
> To the same end, remove the subsequent usage() output for
> some errors as this may be misguiding to a syntax error
> while it wasn't.
> 
> Signed-off-by: Christian Storm <christian.storm@siemens.com>
> ---
>  core/swupdate.c            | 26 ++++++++++++--------------
>  suricatta/server_general.c |  2 +-
>  suricatta/server_hawkbit.c |  2 +-
>  suricatta/suricatta.c      |  2 +-
>  4 files changed, 15 insertions(+), 17 deletions(-)
> 
> diff --git a/core/swupdate.c b/core/swupdate.c
> index 74dfbbe..cc7e2d3 100644
> --- a/core/swupdate.c
> +++ b/core/swupdate.c
> @@ -146,7 +146,7 @@ static void usage(char *programname)
>  		" -N, --no-downgrading <version> : not install a release older as <version>\n"
>  		" -R, --no-reinstalling <version>: not install a release same as <version>\n"
>  		" -M, --no-transaction-marker    : disable setting bootloader transaction marker\n"
> -		" -o, --output <output file>     : saves the incoming stream\n"
> +		" -o, --output <filename>        : saves the incoming stream\n"
>  		" -v, --verbose                  : be verbose, set maximum loglevel\n"
>  		"     --version                  : print SWUpdate version and exit\n"
>  #ifdef CONFIG_HW_COMPATIBILITY
> @@ -700,7 +700,7 @@ int main(int argc, char **argv)
>  		if (read_module_settings(cfgfname, "globals",
>  			read_globals_settings, &swcfg)) {
>  			fprintf(stderr,
> -				 "Error parsing configuration file, exiting..\n");
> +				 "Error parsing configuration file, exiting.\n");
>  			exit(EXIT_FAILURE);
>  		}
>  
> @@ -716,7 +716,7 @@ int main(int argc, char **argv)
>  		 */
>  		if (ret == -EINVAL) {
>  			fprintf(stderr,
> -				 "Error parsing configuration file, exiting..\n");
> +				 "Error parsing configuration file, exiting.\n");
>  			exit(EXIT_FAILURE);
>  		}
>  	}
> @@ -873,7 +873,8 @@ int main(int argc, char **argv)
>  
>  	if (optind < argc) {
>  		/* SWUpdate has no non-option arguments, fail on them */
> -		usage(argv[0]);
> +		fprintf(stderr,
> +			 "Error: Non-option or unrecognized argument(s) given, see --help.\n");
>  		exit(EXIT_FAILURE);
>  	}
>  
> @@ -883,28 +884,25 @@ int main(int argc, char **argv)
>  	 */
>  	if (public_key_mandatory && !strlen(swcfg.globals.publickeyfname)) {
>  		fprintf(stderr,
> -			 "swupdate built for signed image, provide a public key file\n");
> -		usage(argv[0]);
> +			 "Error: SWUpdate is built for signed images, provide a public key file.\n");
>  		exit(EXIT_FAILURE);
>  	}
>  
>  	if (opt_c && !opt_i) {
>  		fprintf(stderr,
> -			"request check for local image, it requires -i\n");
> -		usage(argv[0]);
> +			"Error: Checking local images requires -i <file>.\n");
>  		exit(EXIT_FAILURE);
>  	}
>  
>  	if (opt_i && strlen(swcfg.output)) {
>  		fprintf(stderr,
> -			"Output just from network - do you know cp ?\n");
> -		usage(argv[0]);
> +			"Error: Use cp for -i <image> -o <outfile>.\n");
>  		exit(EXIT_FAILURE);
>  	}
>  
>  #ifdef CONFIG_SURICATTA
>  	if (opt_u && (opt_c || opt_i)) {
> -		fprintf(stderr, "invalid mode combination with suricatta.\n");
> +		fprintf(stderr, "Error: Invalid mode combination with suricatta.\n");
>  		exit(EXIT_FAILURE);
>  	}
>  #endif
> @@ -914,7 +912,7 @@ int main(int argc, char **argv)
>  	if (strlen(swcfg.globals.publickeyfname)) {
>  		if (swupdate_dgst_init(&swcfg, swcfg.globals.publickeyfname)) {
>  			fprintf(stderr,
> -				 "Crypto cannot be initialized\n");
> +				 "Error: Crypto cannot be initialized.\n");
>  			exit(EXIT_FAILURE);
>  		}
>  	}
> @@ -991,7 +989,7 @@ int main(int argc, char **argv)
>  	if (strlen(swcfg.globals.aeskeyfname)) {
>  		if (load_decryption_key(swcfg.globals.aeskeyfname)) {
>  			fprintf(stderr,
> -				"Key file does not contain a valid AES key\n");
> +				"Error: Key file does not contain a valid AES key.\n");
>  			exit(EXIT_FAILURE);
>  		}
>  	}
> @@ -1010,7 +1008,7 @@ int main(int argc, char **argv)
>  
>  	if (opt_e) {
>  		if (parse_image_selector(software_select, &swcfg)) {
> -			fprintf(stderr, "Incorrect select option format\n");
> +			fprintf(stderr, "Error: Incorrect select option format.\n");
>  			exit(EXIT_FAILURE);
>  		}
>  		fprintf(stderr, "software set: %s mode: %s\n",
> diff --git a/suricatta/server_general.c b/suricatta/server_general.c
> index a099d68..5d63207 100644
> --- a/suricatta/server_general.c
> +++ b/suricatta/server_general.c
> @@ -504,7 +504,7 @@ unsigned int server_get_polling_interval(void)
>  void server_print_help(void)
>  {
>  	fprintf(
> -	    stderr,
> +	    stdout,
>  	    "\t  -u, --url         * Host and port of the server instance, "
>  	    "e.g., localhost:8080\n"
>  	    "\t  -p, --polldelay     Delay in seconds between two hawkBit "
> diff --git a/suricatta/server_hawkbit.c b/suricatta/server_hawkbit.c
> index a6ed5a3..29b1ca4 100644
> --- a/suricatta/server_hawkbit.c
> +++ b/suricatta/server_hawkbit.c
> @@ -1565,7 +1565,7 @@ cleanup:
>  void server_print_help(void)
>  {
>  	fprintf(
> -	    stderr,
> +	    stdout,
>  	    "\t  -t, --tenant      * Set hawkBit tenant ID for this device.\n"
>  	    "\t  -u, --url         * Host and port of the hawkBit instance, "
>  	    "e.g., localhost:8080\n"
> diff --git a/suricatta/suricatta.c b/suricatta/suricatta.c
> index cb7c799..ac3be89 100644
> --- a/suricatta/suricatta.c
> +++ b/suricatta/suricatta.c
> @@ -32,7 +32,7 @@ static struct option long_options[] = {
>  void suricatta_print_help(void)
>  {
>  	fprintf(
> -	    stderr,
> +	    stdout,
>  	    "\tsuricatta arguments (mandatory arguments are marked with '*'):\n"
>  	    "\t  -e, --enable      Daemon enabled at startup (default).\n"
>  	    "\t  -d, --disable     Daemon disabled at startup.\n"
> 

Acked-by: Stefano Babic <sbabic@denx.de>

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/core/swupdate.c b/core/swupdate.c
index 74dfbbe..cc7e2d3 100644
--- a/core/swupdate.c
+++ b/core/swupdate.c
@@ -146,7 +146,7 @@  static void usage(char *programname)
 		" -N, --no-downgrading <version> : not install a release older as <version>\n"
 		" -R, --no-reinstalling <version>: not install a release same as <version>\n"
 		" -M, --no-transaction-marker    : disable setting bootloader transaction marker\n"
-		" -o, --output <output file>     : saves the incoming stream\n"
+		" -o, --output <filename>        : saves the incoming stream\n"
 		" -v, --verbose                  : be verbose, set maximum loglevel\n"
 		"     --version                  : print SWUpdate version and exit\n"
 #ifdef CONFIG_HW_COMPATIBILITY
@@ -700,7 +700,7 @@  int main(int argc, char **argv)
 		if (read_module_settings(cfgfname, "globals",
 			read_globals_settings, &swcfg)) {
 			fprintf(stderr,
-				 "Error parsing configuration file, exiting..\n");
+				 "Error parsing configuration file, exiting.\n");
 			exit(EXIT_FAILURE);
 		}
 
@@ -716,7 +716,7 @@  int main(int argc, char **argv)
 		 */
 		if (ret == -EINVAL) {
 			fprintf(stderr,
-				 "Error parsing configuration file, exiting..\n");
+				 "Error parsing configuration file, exiting.\n");
 			exit(EXIT_FAILURE);
 		}
 	}
@@ -873,7 +873,8 @@  int main(int argc, char **argv)
 
 	if (optind < argc) {
 		/* SWUpdate has no non-option arguments, fail on them */
-		usage(argv[0]);
+		fprintf(stderr,
+			 "Error: Non-option or unrecognized argument(s) given, see --help.\n");
 		exit(EXIT_FAILURE);
 	}
 
@@ -883,28 +884,25 @@  int main(int argc, char **argv)
 	 */
 	if (public_key_mandatory && !strlen(swcfg.globals.publickeyfname)) {
 		fprintf(stderr,
-			 "swupdate built for signed image, provide a public key file\n");
-		usage(argv[0]);
+			 "Error: SWUpdate is built for signed images, provide a public key file.\n");
 		exit(EXIT_FAILURE);
 	}
 
 	if (opt_c && !opt_i) {
 		fprintf(stderr,
-			"request check for local image, it requires -i\n");
-		usage(argv[0]);
+			"Error: Checking local images requires -i <file>.\n");
 		exit(EXIT_FAILURE);
 	}
 
 	if (opt_i && strlen(swcfg.output)) {
 		fprintf(stderr,
-			"Output just from network - do you know cp ?\n");
-		usage(argv[0]);
+			"Error: Use cp for -i <image> -o <outfile>.\n");
 		exit(EXIT_FAILURE);
 	}
 
 #ifdef CONFIG_SURICATTA
 	if (opt_u && (opt_c || opt_i)) {
-		fprintf(stderr, "invalid mode combination with suricatta.\n");
+		fprintf(stderr, "Error: Invalid mode combination with suricatta.\n");
 		exit(EXIT_FAILURE);
 	}
 #endif
@@ -914,7 +912,7 @@  int main(int argc, char **argv)
 	if (strlen(swcfg.globals.publickeyfname)) {
 		if (swupdate_dgst_init(&swcfg, swcfg.globals.publickeyfname)) {
 			fprintf(stderr,
-				 "Crypto cannot be initialized\n");
+				 "Error: Crypto cannot be initialized.\n");
 			exit(EXIT_FAILURE);
 		}
 	}
@@ -991,7 +989,7 @@  int main(int argc, char **argv)
 	if (strlen(swcfg.globals.aeskeyfname)) {
 		if (load_decryption_key(swcfg.globals.aeskeyfname)) {
 			fprintf(stderr,
-				"Key file does not contain a valid AES key\n");
+				"Error: Key file does not contain a valid AES key.\n");
 			exit(EXIT_FAILURE);
 		}
 	}
@@ -1010,7 +1008,7 @@  int main(int argc, char **argv)
 
 	if (opt_e) {
 		if (parse_image_selector(software_select, &swcfg)) {
-			fprintf(stderr, "Incorrect select option format\n");
+			fprintf(stderr, "Error: Incorrect select option format.\n");
 			exit(EXIT_FAILURE);
 		}
 		fprintf(stderr, "software set: %s mode: %s\n",
diff --git a/suricatta/server_general.c b/suricatta/server_general.c
index a099d68..5d63207 100644
--- a/suricatta/server_general.c
+++ b/suricatta/server_general.c
@@ -504,7 +504,7 @@  unsigned int server_get_polling_interval(void)
 void server_print_help(void)
 {
 	fprintf(
-	    stderr,
+	    stdout,
 	    "\t  -u, --url         * Host and port of the server instance, "
 	    "e.g., localhost:8080\n"
 	    "\t  -p, --polldelay     Delay in seconds between two hawkBit "
diff --git a/suricatta/server_hawkbit.c b/suricatta/server_hawkbit.c
index a6ed5a3..29b1ca4 100644
--- a/suricatta/server_hawkbit.c
+++ b/suricatta/server_hawkbit.c
@@ -1565,7 +1565,7 @@  cleanup:
 void server_print_help(void)
 {
 	fprintf(
-	    stderr,
+	    stdout,
 	    "\t  -t, --tenant      * Set hawkBit tenant ID for this device.\n"
 	    "\t  -u, --url         * Host and port of the hawkBit instance, "
 	    "e.g., localhost:8080\n"
diff --git a/suricatta/suricatta.c b/suricatta/suricatta.c
index cb7c799..ac3be89 100644
--- a/suricatta/suricatta.c
+++ b/suricatta/suricatta.c
@@ -32,7 +32,7 @@  static struct option long_options[] = {
 void suricatta_print_help(void)
 {
 	fprintf(
-	    stderr,
+	    stdout,
 	    "\tsuricatta arguments (mandatory arguments are marked with '*'):\n"
 	    "\t  -e, --enable      Daemon enabled at startup (default).\n"
 	    "\t  -d, --disable     Daemon disabled at startup.\n"