add sections to config file, supporting multiple pushover apps in the same config file

master
mischa 2023-06-05 16:28:06 +00:00
parent fc2d48d2bb
commit de9fb1cd47
2 changed files with 15 additions and 7 deletions

View File

@ -1,2 +1,8 @@
token = TOKENTOKEN
user = USERUSER
[pushover application]
token = TOKENTOKEN
user = USERUSER
[application]
token = TOKENTOKEN
user = USERUSER

View File

@ -28,22 +28,24 @@ GetOptions(
"title=s" => \(my $TITLE = "Notification"),
"priority=i" => \(my $PRIORITY = 0),
"config=s" => \(my $CONFIG),
"application=s" => \(my $APPLICATION = '_'),
);
my $USAGE = <<"END_USAGE";
Usage: $0 [-m message] [-t title] [-p priority]
Usage: $0 -m message [-t title] [-p priority] [-a application] [-c config]
Options:
-m | --message text
-t | --title text (default: Notification)
-p | --priority [0|1] (default: 0)
-c | --config text
-m | --message text
-t | --title text | (default: Notification)
-p | --priority [0|1] (default: 0)
-a | --application text (default: root property of config)
-c | --config text (no default)
END_USAGE
$MESSAGE || die($USAGE);
my @config_files = $CONFIG || grep { -e } ('./_pushover.conf', './.pushover.conf', './pushover.conf', "$ENV{'HOME'}/_pushover.conf", "$ENV{'HOME'}/.pushover.conf", "$ENV{'HOME'}/pushover.conf");
my $config = Config::Tiny->read($config_files[-1], 'utf8');
my $TOKEN = $config->{_}->{token} || die("$USAGE\nError: TOKEN not found.\n");
my $USER = $config->{_}->{user} || die("$USAGE\nError: USER not found.\n");
my $TOKEN = $config->{$APPLICATION}->{token} || die("$USAGE\nError: TOKEN not found.\n");
my $USER = $config->{$APPLICATION}->{user} || die("$USAGE\nError: USER not found.\n");
my $http = HTTP::Tiny->new;
my %HEADERS = ("Content-Type" => "application/json");