--- a/src/nexus.c Wed Apr 01 00:57:34 2009 +0300
+++ b/src/nexus.c Wed Apr 01 01:41:08 2009 +0300
@@ -1,5 +1,5 @@
#include "nexus.h"
-#include "signals.h"
+#include "lua_config.h"
#include "log.h"
#include <stdlib.h>
@@ -16,15 +16,16 @@
OPT_HELP = 'h',
OPT_DEFAULTS = 'D',
OPT_NETWORK = 'n',
- OPT_CHANNEL = 'c',
OPT_MODULE = 'm',
- OPT_CONFIG = 'C',
+ OPT_CONF = 'C',
OPT_DEBUG = 'd',
+ OPT_CONFIG = 'c',
/** Options without short names */
_OPT_EXT_BEGIN = 0x00ff,
OPT_CONSOLE,
+ OPT_CHANNEL,
};
/**
@@ -36,13 +37,19 @@
{"network", 1, NULL, OPT_NETWORK },
{"channel", 1, NULL, OPT_CHANNEL },
{"module", 1, NULL, OPT_MODULE },
- {"config", 1, NULL, OPT_CONFIG },
+ {"conf", 1, NULL, OPT_CONF },
{"debug", 0, NULL, OPT_DEBUG },
{"console", 0, NULL, OPT_CONSOLE },
+ {"config", 1, NULL, OPT_CONFIG },
{0, 0, 0, 0 },
};
/**
+ * Short command-line option defintion
+ */
+const char *short_options = "hn:c:m:C:d";
+
+/**
* Display --help output on stdout.
*
* If nexus is given, --config options for loaded modules are also listed
@@ -54,10 +61,11 @@
printf(" --help / -h display this message\n");
printf(" --defaults / -D set the IRC client default info using '<nickname>:<username>:<realname>'\n");
printf(" --network / -n add an IRC network using '<name>:<hostname>[:<port>[:ssl]]' format\n");
- printf(" --channel / -c add an IRC channel using '<network>:<channel>' format\n");
+ printf(" --channel add an IRC channel using '<network>:<channel>' format\n");
printf(" --module / -m add a module using '<name>:<path>' format\n");
printf(" --config / -C add a module configuration option using '<mod_name>:<name>[:<value>]' format\n");
printf(" --debug / -d set logging level to DEBUG\n");
+ printf(" --config / -c load a Lua config file from '<path>'\n");
printf(" --console use the interactive console\n");
// dump loaded module configs
@@ -232,9 +240,9 @@
}
/**
- * Parse and apply a --config option, calling the module's conf func.
+ * Parse and apply a --conf option, calling the module's conf func.
*/
-static err_t apply_config (struct nexus *nexus, char *opt, struct error_info *err)
+static err_t apply_conf (struct nexus *nexus, char *opt, struct error_info *err)
{
struct module *module;
const char *module_name, *conf_name;
@@ -294,6 +302,16 @@
}
/**
+ * Load the lua config file from \a path
+ */
+static err_t apply_config (struct nexus *nexus, char *path, struct error_info *err)
+{
+ log_info("loading lua config from %s", path);
+
+ return lua_config_load(nexus->lua, path, err);
+}
+
+/**
* Parse arguments and apply them to the given nexus
*/
static err_t parse_args (struct nexus *nexus, int argc, char **argv, struct error_info *err)
@@ -301,7 +319,7 @@
int opt, option_index;
// parse options
- while ((opt = getopt_long(argc, argv, "hn:c:m:C:", options, &option_index)) != -1) {
+ while ((opt = getopt_long(argc, argv, short_options, options, &option_index)) != -1) {
switch (opt) {
case OPT_HELP:
usage(nexus, argv[0]);
@@ -333,8 +351,8 @@
break;
- case OPT_CONFIG:
- if (apply_config(nexus, optarg, err))
+ case OPT_CONF:
+ if (apply_conf(nexus, optarg, err))
return ERROR_CODE(err);
break;
@@ -348,6 +366,12 @@
return ERROR_CODE(err);
break;
+
+ case OPT_CONFIG:
+ if (apply_config(nexus, optarg, err))
+ return ERROR_CODE(err);
+
+ break;
case '?':
usage(nexus, argv[0]);