- my $arg = 0;
- while (defined($ARGV[$arg])) {
- for ($ARGV[$arg]) {
- /--help/ && do {
- print_help ();
- return FALSE;
- };
- /--version/ && do {
- print_version ();
- return FALSE;
- };
- /--verbose/ && do {
- $VERBOSE = TRUE;
- last;
- };
- /--use-claws-version/ && do {
- ++$arg;
- command_line_fatal ("required version")
- unless defined($ARGV[$arg]);
- command_line_fatal ("required a dotted numeric value")
- unless ($ARGV[$arg] =~ /[\d\.]+/);
- $CLAWSV = $ARGV[$arg];
- last;
- };
- /--alternate-config-dir/ && do {
- ++$arg;
- command_line_fatal ($xl::s{e_requireddir})
- unless defined($ARGV[$arg]);
- command_line_fatal ($xl::s{e_notadir})
- unless -d $ARGV[$arg];
- $CONFIGDIR = $ARGV[$arg];
- $CONFIGDIR .= "/"
- unless ($CONFIGDIR =~ /.*\/$/);
- $ALTCONFIGDIR = TRUE;
- last;
- };
- /--clawsrc/ && do {
- ++$arg;
- command_line_fatal($xl::s{e_requiredfile})
- unless defined($ARGV[$arg]);
- command_line_fatal($xl::s{e_notafile})
- unless -f $ARGV[$arg];
- set_rc_filename ($ARGV[$arg]);
- last;
- };
- /.*/ && command_line_fatal (
- _("unknown option '{opt}'.\n", opt => $ARGV[$arg]));
- }
- ++$arg;
- }
- # eveything continues...
- return TRUE;
+ eval {
+ GetOptions('h|help' => sub { print_help (); $cont = FALSE },
+ 'v|version' => sub { print_version (); $cont = FALSE },
+ 'b|verbose' => sub { $VERBOSE = TRUE },
+ 'u|use-claws-version=s' => \&opt_use_claws_version,
+ 'a|alternate-config-dir=s' => \&opt_alternate_config_dir,
+ 'r|clawsrc=s' => \&opt_clawsrc)
+ or die _("try -h or --help for syntax.\n");
+ };
+ die _("Error in options: {msg}\n", msg => $@) if $@;
+ return $cont;
+}
+
+sub opt_use_claws_version {
+ my ($name, $value) = @_;
+ die _("Error: {opt} requires a dotted numeric value argument\n", opt => $name)
+ unless ($value =~ /^[\d\.]+$/);
+ $CLAWSV = $value;
+}
+
+sub opt_alternate_config_dir {
+ my ($name, $value) = @_;
+ die _("Error: '{dir}' is not a directory or does not exist\n", dir => $value)
+ unless -d $value;
+ $CONFIGDIR = $value;
+ $CONFIGDIR .= "/" unless ($CONFIGDIR =~ /.*\/$/);
+ $ALTCONFIGDIR = TRUE;
+}
+
+sub opt_clawsrc {
+ my ($name, $value) = @_;
+ die _("Error: '{value}' is not a file or does not exist", value => $value)
+ unless -f $value;
+ set_rc_filename ($value);