Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 22 additions & 23 deletions script/le.pl
Original file line number Diff line number Diff line change
Expand Up @@ -425,20 +425,30 @@ sub encode_args {

sub parse_config {
my ($opt) = @_;
unless ($opt) {
return sub {
return { code => 1, msg => shift }
my $debug = 0;
my $errors = {
# NB: Early renewal stop is not considered an error by default.
EXPIRATION_EARLY => 0,
};
my $error_sub = sub { # closes upon $debug and $errors above
my ($msg, $code) = @_;
if ($code and $code!~/^\d+$/) {
# Unless associated with 0 exit value, in debug mode
# prefix the message with a passed down code.
unless (!$debug or (defined $errors->{$code} and !$errors->{$code})) {
$msg = "[ $code ] " . ($msg || '');
}
$code = $errors->{$code};
}
return { msg => $msg, code => $code };
};
unless ($opt) {
return $error_sub;
}
if (my $config = _read($opt->{'config'})) {
# INI-like, simplified.
my ($cl, $section) = (0, '');
my $sections = {
errors => {
# NB: Early renewal stop is not considered an error by default.
EXPIRATION_EARLY => 0,
},
};
my $sections = { errors => { %$errors } };
for (split /\r?\n/, $config) {
$cl++;
next if /^\s*(?:;|#)/;
Expand All @@ -454,20 +464,9 @@ sub parse_config {
}
}
# Process errors section.
my $debug = $opt->{'debug'};
my $errors = delete $sections->{'errors'};
$opt->{'error'} = sub {
my ($msg, $code) = @_;
if ($code and $code!~/^\d+$/) {
# Unless associated with 0 exit value, in debug mode
# prefix the message with a passed down code.
unless (!$debug or (defined $errors->{$code} and !$errors->{$code})) {
$msg = "[ $code ] " . ($msg || '');
}
$code = $errors->{$code};
}
return { msg => $msg, code => $code };
};
$debug = $opt->{'debug'};
$errors = delete $sections->{'errors'};
$opt->{'error'} = $error_sub;
return;
} else {
return "Could not read config file.";
Expand Down