* nih/option.c (nih_option_help): Allow the usage string to be
customised.
(nih_option_set_usage): Using this function.
* nih/option.h: Update.
* nih/tests/test_option.c (test_help): Test the usage string.
diff --git a/ChangeLog b/ChangeLog
index 9250fa7..ef936ad 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
2006-09-08 Scott James Remnant <scott@netsplit.com>
+ * nih/option.c (nih_option_help): Allow the usage string to be
+ customised.
+ (nih_option_set_usage): Using this function.
+ * nih/option.h: Update.
+ * nih/tests/test_option.c (test_help): Test the usage string.
+
* nih/main.c (nih_main_daemonise): Use program_name for the pid file.
* nih/main.h: Update.
diff --git a/nih/option.c b/nih/option.c
index ddddcd4..2f2a7ee 100644
--- a/nih/option.c
+++ b/nih/option.c
@@ -107,6 +107,13 @@
NIH_OPTION_LAST
};
+/**
+ * usage_string:
+ *
+ * This string is appended to the program help if given.
+ **/
+static const char *usage_string = NULL;
+
/**
* nih_option_parser:
@@ -626,6 +633,21 @@
/**
+ * nih_option_set_usage:
+ * @usage: usage string.
+ *
+ * Set the usage string appended to the program help output, this should
+ * be a static translated string.
+ **/
+void
+nih_option_set_usage (const char *usage)
+{
+ nih_assert (usage != NULL);
+
+ usage_string = usage;
+}
+
+/**
* nih_option_help:
* @options: program options lists.
*
@@ -672,8 +694,9 @@
}
}
- /* FIXME ideally this header should be changeable */
- printf ("%s: %s [OPTION]... [ARG]...\n", _("Usage"), program_name);
+ printf ("%s: %s [OPTION]...", _("Usage"), program_name);
+ if (usage_string)
+ printf (" %s", usage_string);
printf ("\n");
/* Iterate the option groups we found in order, and display
diff --git a/nih/option.h b/nih/option.h
index 1f3b659..5a93197 100644
--- a/nih/option.h
+++ b/nih/option.h
@@ -103,15 +103,16 @@
NIH_BEGIN_EXTERN
-char **nih_option_parser (void *parent, int argc, char *argv[],
- NihOption *options, int break_nonopt);
+char **nih_option_parser (void *parent, int argc, char *argv[],
+ NihOption *options, int break_nonopt);
-int nih_option_count (NihOption *option, const char *arg);
-int nih_option_quiet (NihOption *option, const char *arg);
-int nih_option_verbose (NihOption *option, const char *arg);
-int nih_option_debug (NihOption *option, const char *arg);
+int nih_option_count (NihOption *option, const char *arg);
+int nih_option_quiet (NihOption *option, const char *arg);
+int nih_option_verbose (NihOption *option, const char *arg);
+int nih_option_debug (NihOption *option, const char *arg);
-void nih_option_help (NihOption *options[]);
+void nih_option_set_usage (const char *usage);
+void nih_option_help (NihOption *options[]);
NIH_END_EXTERN
diff --git a/nih/tests/test_option.c b/nih/tests/test_option.c
index fa5d074..21c2cb1 100644
--- a/nih/tests/test_option.c
+++ b/nih/tests/test_option.c
@@ -1982,6 +1982,10 @@
pid_t pid;
int ret = 0, argc, status;
+ printf ("Testing nih_option_set_usage()\n");
+ nih_option_set_usage ("CMD [ARG]...\n");
+
+
printf ("Testing nih_option_help()\n");
program_name = "test";
package_bugreport = "foo@bar.com";
@@ -2010,7 +2014,7 @@
/* First line of output should be usage string */
fgets (text, sizeof (text), output);
- if (strcmp (text, "Usage: test [OPTION]... [ARG]...\n")) {
+ if (strcmp (text, "Usage: test [OPTION]... CMD [ARG]...\n")) {
printf ("BAD: usage line wasn't what we expected.\n");
ret = 1;
}