-my $arg = $ARGV[0];
-getpidfile($confpath."inspircd.conf");
-
-if ($arg eq "start") { start(); exit(); }
-if ($arg eq "debug") { debug(); exit(); }
-if ($arg eq "screendebug") { screendebug(); exit() }
-if ($arg eq "valdebug") { valdebug(); exit(); }
-if ($arg eq "valdebug-unattended") { valdebugunattended(); exit(); }
-if ($arg eq "screenvaldebug") { screenvaldebug(); exit(); }
-if ($arg eq "stop") { stop(); exit(); }
-if ($arg eq "status") {
+my $arg = shift(@ARGV);
+my $conf = $confpath . "inspircd.conf";
+for my $a (@ARGV)
+{
+ if ($a =~ m/^--config=(.*)$/)
+ {
+ $conf = $1;
+ last;
+ }
+}
+getpidfile($conf);
+
+# System for naming script command subs:
+# cmd_<name> - Normal command for use by users.
+# dev_<name> - Developer commands.
+# hid_<name> - Hidden commands (ie Cheese-Sandwich)
+# Ideally command subs shouldn't return.
+
+my $subname = $arg;
+$subname =~ s/-/_/g;
+my $sub = main->can("cmd_$subname") || main->can("dev_$subname") || main->can("hid_$subname");
+if (!defined($sub))
+{
+ print STDERR "Invalid command or none given.\n";
+ cmd_help();
+ exit 1;
+}
+else
+{
+ $sub->(@ARGV);
+ exit 0;
+}
+
+sub cmd_help()
+{
+ my @subs = grep { $_ =~ m/^(cmd|dev)_/ && defined(main->can($_)) } keys(%::);
+ my @cmds = grep /^cmd_/, @subs;
+ my @devs = grep /^dev_/, @subs;
+ local $_;
+ $_ =~ s/^(cmd|dev)_// foreach (@cmds, @devs);
+ $_ =~ s/_/-/g foreach (@cmds, @devs);
+ print STDERR "Usage: ./inspircd (" . join("|", @cmds) . ")\n";
+ print STDERR "Developer arguments: (" . join("|", @devs) . ")\n";
+ exit 0;
+}
+
+sub cmd_status()
+{