aboutsummaryrefslogtreecommitdiff
path: root/bin/events2md.pl
diff options
context:
space:
mode:
Diffstat (limited to 'bin/events2md.pl')
-rwxr-xr-xbin/events2md.pl32
1 files changed, 23 insertions, 9 deletions
diff --git a/bin/events2md.pl b/bin/events2md.pl
index dfa1b2b..f9363f9 100755
--- a/bin/events2md.pl
+++ b/bin/events2md.pl
@@ -9,6 +9,10 @@ use FindBin qw($Bin);
use lib "$Bin/../lib";
use Getopt::Complete (
+ 'quiet!' => undef,
+ 'verbose!' => undef,
+ 'debug!' => undef,
+ 'trace!' => undef,
'output' => undef,
'skeldir' => 'directories',
'username' => undef,
@@ -31,13 +35,6 @@ use DateTime::TimeZone;
use Object::Groupware::DAV;
use Object::Groupware::Calendar;
-if ( IO::Interactive::Tiny::is_interactive() ) {
- Log::Any::Adapter->set( 'Screen', default_level => 'info' );
-}
-else {
- use Log::Any::Adapter ( 'Stderr', default_level => 'info' );
-}
-
# collect settings from command-line options and defaults
my $SKELDIR = $ARGS{skeldir} || $ENV{SKELDIR} || "$Bin/../templates";
my $BASE_URI = $ARGS{'<>'}[0] || $ENV{CAL_DAV_URL_BASE};
@@ -48,6 +45,20 @@ my $LOCALE = $ARGS{locale} || $ENV{CAL_LANG};
my $TIME_ZONE = $ARGS{timezone};
my $OUTPUT_FILE = $ARGS{output};
+# init logging
+my $LOGLEVEL = 'warning';
+$LOGLEVEL = 'critical' if $ARGS{quiet};
+$LOGLEVEL = 'warning' if defined $ARGS{verbose} and !$ARGS{verbose};
+$LOGLEVEL = 'info' if $ARGS{verbose};
+$LOGLEVEL = 'debug' if $ARGS{debug};
+$LOGLEVEL = 'trace' if $ARGS{trace};
+if ( IO::Interactive::Tiny::is_interactive() ) {
+ Log::Any::Adapter->set( 'Screen', default_level => $LOGLEVEL );
+}
+else {
+ use Log::Any::Adapter ( 'Stderr', default_level => $LOGLEVEL );
+}
+
# extend DateTime locale with form LONGER
# * omit year and second
# * unabbreviate weekday and month
@@ -82,6 +93,8 @@ $dt_locale_data{time_format_medium} = $dt->locale->format_for('Hm');
$dt_locale_data{datetime_format_medium}
=~ s/^\{1\}\K,? (?=\{0\}$)/$at{$lang}/
if $at{$lang};
+
+# init groupware settings
my %GROUPWARE_OPTIONS = (
dt_locale => DateTime::Locale::FromData->new( \%dt_locale_data ),
dt_time_zone => DateTime::TimeZone->new(
@@ -94,13 +107,14 @@ $log->infof(
$GROUPWARE_OPTIONS{dt_time_zone}->name,
);
-# resolve calendar URIs
-my $calendar;
+# init calendar URIs
$BASE_URI = URI->new($BASE_URI)
or $log->fatal('failed to parse required base URI') && exit 2;
$BASE_URI->scheme
or $BASE_URI->scheme('file');
+# get calendar
+my $calendar;
if ( $BASE_URI->scheme eq 'http' or $BASE_URI->scheme eq 'https' ) {
$log->infof( 'will use base URI %s', $BASE_URI );
$CALENDAR_URI = URI->new( $CALENDAR_URI || $BASE_URI );