[pacman-dev,2/5] pacman-conf: simplify usage()

Message ID 20180209044908.22901-3-iff@escondida.tk
State Superseded, archived
Delegated to: Andrew Gregory
Headers show
Series Miscellaneous pacman-conf tweaks | expand

Commit Message

Ivy Foster Feb. 9, 2018, 4:49 a.m. UTC
From: Ivy Foster <iff@escondida.tk>

Signed-off-by: Ivy Foster <iff@escondida.tk>
---
 src/pacman/pacman-conf.c | 40 ++++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 20 deletions(-)

Patch

diff --git a/src/pacman/pacman-conf.c b/src/pacman/pacman-conf.c
index 5347a837..a503ece9 100644
--- a/src/pacman/pacman-conf.c
+++ b/src/pacman/pacman-conf.c
@@ -34,24 +34,21 @@  static void cleanup(void)
 	config_free(config);
 }
 
-static void usage(int ret)
+static void usage(FILE *stream)
 {
-	FILE *stream = (ret ? stderr : stdout);
-#define hputs(x) fputs(x"\n", stream)
-	hputs("pacman-conf - query pacman's configuration file");
-	hputs("usage:  pacman-conf [options] [<directive>...]");
-	hputs("        pacman-conf (--repo-list|--help|--version)");
-	hputs("options:");
-	hputs("  --config=<path>  set an alternate configuration file");
-	hputs("  --rootdir=<path> set an alternate installation root");
-	hputs("  --repo=<remote>  query options for a specific repo");
-	hputs("  --verbose        always show directive names");
-	hputs("  --repo-list      list configured repositories");
-	hputs("  --help           display this help information");
-	hputs("  --version        display version information");
-#undef hputs
-	cleanup();
-	exit(ret);
+	static const char help[] =
+		"pacman-conf: query pacman's configuration file\n"
+		"usage: pacman-conf [options] [directive]\n"
+		"       pacman-conf [ { -l, --repo-list } | { -h, --help } | { -V, --version } ]\n"
+		"options:\n"
+		"    -c, --config=<file>  Read configuration from <file>\n"
+		"    -h, --help           Print help\n"
+		"    -l, --repo-list      List configured repositories\n"
+		"    -r, --repo=<remote>  Query options for a specific repo\n"
+		"    -R, --rootdir=<dir>  Use <dir> as system root\n"
+		"    -v, --verbose        Always show directive names\n"
+		"    -V, --version        Print version\n";
+	fprintf(stream, "%s", help);
 }
 
 static void parse_opts(int argc, char **argv)
@@ -90,15 +87,18 @@  static void parse_opts(int argc, char **argv)
 				break;
 			case 'h':
 			case '?':
-				usage(0);
-				break;
+				usage(stdout);
+				cleanup();
+				exit(0);
 			case 'V':
 				printf("%s v%s\n", myname, myver);
 				cleanup();
 				exit(0);
 				break;
 			default:
-				usage(1);
+				usage(stderr);
+				cleanup();
+				exit(1);
 				break;
 		}
 	}